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

« back to all changes in this revision

Viewing changes to tests/simulate/string/strcasecmp.c

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2009-10-31 11:52:10 UTC
  • mfrom: (1.1.8 upstream) (4.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091031115210-x0mlijnegkce86fk
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: strcasecmp.c,v 1.1 2007/02/24 14:20:17 dmix Exp $       */
2
 
 
3
 
#ifndef __AVR__
4
 
# include <stdio.h>
5
 
#endif
6
 
#include <stdlib.h>
7
 
#include <string.h>
8
 
#include "progmem.h"
9
 
 
10
 
void Check (int line, const char *s1, const char *s2, int expect)
11
 
{
12
 
    char t1[200];
13
 
    char t2[200];
14
 
    int i;
15
 
    if (   strlen_P(s1) > sizeof(t1) - 1
16
 
        || strlen_P(s2) > sizeof(t2) - 1)
17
 
      exit (1);
18
 
    strcpy_P (t1, s1);
19
 
    strcpy_P (t2, s2);
20
 
    i = strcasecmp (t1, t2);
21
 
    if (i == expect)
22
 
        return;
23
 
#if     !defined(__AVR__)
24
 
    printf ("\nLine %d: expect: %d, result: %d\n",
25
 
            line, expect, i);
26
 
    if (line > 255) line = 255;
27
 
#elif   defined(DEBUG)
28
 
    exit (i);
29
 
#endif
30
 
    exit (line);
31
 
}
32
 
 
33
 
#define CHECK(s1, s2, expect)   do {                    \
34
 
    Check (__LINE__, PSTR(s1), PSTR(s2), expect);       \
35
 
} while (0)
36
 
 
37
 
int main ()
38
 
{
39
 
    /* One or both strings are empty.   */
40
 
    CHECK ("", "", 0);
41
 
    CHECK ("", "\001", -1);
42
 
    CHECK ("", "\377", -255);
43
 
    CHECK ("\001", "", 1);
44
 
    CHECK ("\377", "", 255);
45
 
 
46
 
    /* bug #19134       */
47
 
    CHECK ("a", "[", 'a' - '[');
48
 
    CHECK ("[", "a", '[' - 'a');
49
 
 
50
 
    /* Agrs are equal.  */
51
 
    CHECK ("\001", "\001", 0);
52
 
    CHECK ("1234\377", "1234\377", 0);
53
 
    CHECK ("ABC", "abc", 0);
54
 
    CHECK ("FoO", "fOO", 0);
55
 
 
56
 
    /* Args are not equal.      */
57
 
    CHECK ("@", "`", '@' - '`');        /* '@'=='A'-1, '`'=='a'-1       */
58
 
    CHECK ("{", "[", '{' - '[');        /* '{'=='z'+1, '['=='A'+1       */
59
 
 
60
 
    /* Alpha is always converted to lower       */
61
 
    CHECK ("1", "A", '1'-'a');
62
 
    CHECK ("Z", "2", 'z'-'2');
63
 
 
64
 
    /* Chars are unsigned       */
65
 
    CHECK ("\200", "\177", 1);
66
 
    CHECK ("\177", "\200", -1);
67
 
    CHECK ("\001", "\377", -254);
68
 
    CHECK ("\377", "\001", 254);
69
 
 
70
 
    return 0;
71
 
}