~ubuntu-branches/ubuntu/raring/avr-libc/raring-proposed

« back to all changes in this revision

Viewing changes to tests/simulate/pmstring/strstr_P.c

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2008-08-10 09:59:16 UTC
  • mfrom: (1.1.7 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080810095916-wwyigh3vt0e9s7ud
Tags: 1:1.6.2.cvs20080610-2
Added build-depends on texlive-extra-utils (closes: #493454)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: strstr_P.c,v 1.1 2007/03/01 13:12:09 dmix Exp $ */
 
2
 
 
3
#ifndef __AVR__
 
4
# include <stdio.h>
 
5
# define strstr_P  strstr
 
6
#endif
 
7
#include <stdlib.h>
 
8
#include <string.h>
 
9
#include "progmem.h"
 
10
 
 
11
void Check (int line, const char *s1, const char *s2, int expect)
 
12
{
 
13
    char t1[200];
 
14
    char *p;
 
15
 
 
16
    if (strlen_P(s1) > sizeof(t1) - 1)
 
17
        exit (1);
 
18
    strcpy_P (t1, s1);
 
19
    p = strstr_P (t1, s2);
 
20
    if ((!p && expect == -1)  || (p == t1 + expect))
 
21
        return;
 
22
#if     !defined(__AVR__)
 
23
    printf ("\nLine %d: expect: %d, result: %d\n",
 
24
            line, expect, (p ? p - t1 : -1));
 
25
    if (line > 255) line = 255;
 
26
#elif   defined(DEBUG)
 
27
    exit (p ? p - t1 : -1);
 
28
#endif
 
29
    exit (line);
 
30
}
 
31
 
 
32
#define CHECK(s1, s2, expect)   do {                    \
 
33
    Check (__LINE__, PSTR(s1), PSTR(s2), expect);       \
 
34
} while (0)
 
35
 
 
36
int main ()
 
37
{
 
38
    /* Empty 'needle'.  */
 
39
    CHECK ("", "", 0);
 
40
    CHECK ("12345", "", 0);
 
41
 
 
42
    /* bug #19135       */
 
43
    CHECK ("ababac", "abac", 2);
 
44
 
 
45
    /* 'needle' of 1 byte long  */
 
46
    CHECK ("", "a", -1);
 
47
    CHECK ("b", "a", -1);
 
48
    CHECK ("a", "a", 0);
 
49
    CHECK ("abcbef", "a", 0);
 
50
    CHECK (".a", "a", 1);
 
51
    CHECK (".a.", "a", 1);
 
52
    CHECK ("ABCDEFGH", "H", 7);
 
53
    
 
54
    /* 'needle' of 2 bytes long */
 
55
    CHECK ("", "12", -1);
 
56
    CHECK ("13", "12", -1);
 
57
    CHECK ("32", "12", -1);
 
58
    CHECK ("12", "12", 0);
 
59
    CHECK ("123", "12", 0);
 
60
    CHECK ("012", "12", 1);
 
61
    CHECK ("01200", "12", 1);
 
62
    
 
63
    /* partially mathing        */
 
64
    CHECK ("a_ab_abc_abcd_abcde", "abcdef", -1);
 
65
    CHECK ("a_ab_abc_abcd_abcde_abcdef", "abcdef", 20);
 
66
    CHECK ("aababcabcdabcde", "abcdef", -1);
 
67
    CHECK ("aababcabcdabcdeabcdef", "abcdef", 15);
 
68
    
 
69
    /* repeated chars   */
 
70
    CHECK ("abaabaaabaaaab", "aaaaab", -1);
 
71
    CHECK ("abaabaaabaaaabaaaaab", "aaaaab", 14);
 
72
    
 
73
    /* A first match is returned.       */
 
74
    CHECK ("_foo_foo", "foo", 1);
 
75
    
 
76
    /* Case is importent.       */
 
77
    CHECK ("A", "a", -1);
 
78
 
 
79
    return 0;
 
80
}