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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2009-10-31 11:52:10 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20091031115210-crjd42sn6ezrj52c
Tags: 1:1.6.7-1
* New upstream relese (closes: #544030)
* Added lintian overrides (closes: #553265)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: strrchr_P.c,v 1.1 2007/03/01 13:06:02 dmix Exp $        */
2
 
 
3
 
#ifndef __AVR__
4
 
# include <stdio.h>
5
 
# define strrchr_P  strrchr
6
 
#endif
7
 
#include <stdlib.h>
8
 
#include <string.h>
9
 
#include "progmem.h"
10
 
 
11
 
void Check (int line, const char *s, int c, int expect)
12
 
{
13
 
    const char *p;
14
 
    p = strrchr_P (s, c);
15
 
    if (expect == -1 && !p)
16
 
        return;
17
 
    if (s + expect == p)
18
 
        return;
19
 
#ifndef __AVR__
20
 
    printf ("\nLine %d: expect: %d, result: %d\n",
21
 
            line, expect, (p ? p-s : -1));
22
 
#endif
23
 
    exit (line);
24
 
}
25
 
 
26
 
#define CHECK(s, c, expect)     do {            \
27
 
    Check (__LINE__, PSTR(s), c, expect);       \
28
 
} while (0)
29
 
 
30
 
int main ()
31
 
{
32
 
    /* Not found        */
33
 
    CHECK ("", 1, -1);
34
 
    CHECK ("", 255, -1);
35
 
    CHECK ("ABCDEF", 'a', -1);
36
 
    
37
 
    /* Found    */
38
 
    CHECK ("\001", 1, 0);
39
 
    CHECK ("\377", 255, 0);
40
 
    CHECK ("987654321", '7', 2);
41
 
 
42
 
    /* '\0' is a part of string */
43
 
    CHECK ("12345", 0, 5);
44
 
    CHECK ("", 0, 0);
45
 
 
46
 
    /* Last occurance   */
47
 
    CHECK ("00", '0', 1);
48
 
    CHECK ("abcdabcd", 'b', 5);
49
 
    CHECK ("***********", '*', 10);
50
 
    
51
 
    /* 'c' converted to a char  */
52
 
    CHECK ("ABCDEF", 'A'+0x100, 0);
53
 
    CHECK ("ABCDE\377", ~0, 5);
54
 
    CHECK ("+", ~0xff, 1);
55
 
    
56
 
    /* Very long string */
57
 
    CHECK ("................................................................"
58
 
           "................................................................"
59
 
           "................................................................"
60
 
           "................................................................"
61
 
           "*...............", '*', 256);
62
 
 
63
 
    return 0;
64
 
}