~ubuntu-branches/ubuntu/trusty/avr-libc/trusty

« back to all changes in this revision

Viewing changes to tests/simulate/string/strcmp.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: strcmp.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 = strcmp (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
 
    /* Agrs are equal.  */
47
 
    CHECK ("\001", "\001", 0);
48
 
    CHECK ("1234\377", "1234\377", 0);
49
 
    CHECK ("ABC", "ABC", 0);
50
 
    CHECK ("foo", "foo", 0);
51
 
 
52
 
    /* Args are not equal.      */
53
 
    CHECK ("ABCDEF", "ABCDE", 'F');
54
 
    CHECK ("abcde", "abcdef", -'f');
55
 
    CHECK ("12345", "12245", 1);
56
 
 
57
 
    /* Case is important.       */
58
 
    CHECK ("xyz", "xYz", 'y'-'Y');
59
 
    CHECK ("QUICK", "qUICK", 'Q'-'q');
60
 
 
61
 
    /* Chars are unsigned       */
62
 
    CHECK ("\200", "\177", 1);
63
 
    CHECK ("\177", "\200", -1);
64
 
    CHECK ("\001", "\377", -254);
65
 
    CHECK ("\377", "\001", 254);
66
 
 
67
 
    return 0;
68
 
}