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

« back to all changes in this revision

Viewing changes to tests/simulate/stdlib/toupper-1.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
 
/* Test of toupper() function.
2
 
   $Id: toupper-1.c,v 1.1.2.1 2008/03/20 21:42:38 joerg_wunsch Exp $
3
 
 */
4
 
#include <ctype.h>
5
 
#include <stdlib.h>
6
 
#include <stdio.h>
7
 
 
8
 
#ifndef __AVR__
9
 
# define PRINTFLN(fmt, ...)     \
10
 
    printf ("\nLine %d: " fmt "\n", __LINE__, ##__VA_ARGS__)
11
 
# define EXIT(code)     exit ((code) < 255 ? (code) : 100 + (code) % 100)
12
 
#else
13
 
# if defined(__AVR_ATmega128__)
14
 
  /* ATmega128 has enough RAM for sprintf(), print to 0x2000 in XRAM. */
15
 
#  define PRINTFLN(fmt, ...)    \
16
 
    sprintf ((char *)0x2000, "\nLine %d: " fmt "\n", __LINE__, ##__VA_ARGS__)
17
 
# else
18
 
   /* small AVR */
19
 
#  define PRINTFLN(args...)
20
 
# endif
21
 
# define EXIT   exit
22
 
#endif
23
 
 
24
 
int main ()
25
 
{
26
 
    int i, v;
27
 
    
28
 
    for (i = -1; i < 256; i++) {
29
 
        v = toupper (i);
30
 
        if (i >= 'a' && i <= 'z') {
31
 
            if (v != i + 'A' - 'a') {
32
 
                PRINTFLN ("toupper(%#x) --> %#x", i, v);
33
 
                EXIT (__LINE__);
34
 
            }
35
 
        } else {
36
 
            if (v != i) {
37
 
                PRINTFLN ("toupper(%#x) --> %#x", i, v);
38
 
                EXIT (__LINE__);
39
 
            }
40
 
        }
41
 
    }
42
 
    
43
 
 
44
 
/* Skip the host, as according to C standart it is not safety to use an
45
 
   argument beyound -1..255 value. Avr-libc's ctype functions permit
46
 
   this.        */
47
 
#ifdef  __AVR__
48
 
    {
49
 
        unsigned int u;
50
 
        for (u = 0xffff; u > 0xff; u--)
51
 
            if (u != (unsigned int)toupper (u))
52
 
                EXIT (__LINE__);
53
 
    }
54
 
#endif
55
 
 
56
 
    return 0;
57
 
}