Changeset 38407
- Timestamp:
- Jun 6, 2015, 10:04:22 AM (11 years ago)
- Location:
- branches/eam_branches/ohana.20150429/src/libohana
- Files:
-
- 2 edited
-
Makefile (modified) (1 diff)
-
test/typetest.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20150429/src/libohana/Makefile
r38377 r38407 66 66 $(TESTPROG) : % : $(TESTBIN)/% $(OBJS) 67 67 test: $(TESTPROG) 68 for i in $(TESTPROG); do $(TESTBIN)/$$i; done 69 68 for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 | $(TESTHARNESS); done 69 test.verbose: $(TESTPROG) 70 for i in $(TESTPROG); do $(TESTBIN)/$$i 2>&1 |& $(TESTHARNESS) -v; done -
branches/eam_branches/ohana.20150429/src/libohana/test/typetest.c
r31663 r38407 1 1 # include "ohana.h" 2 # include "tap_ohana.h" 2 3 3 4 enum 4 {5 { 5 6 OHANA_LITTLE_ENDIAN = 0x03020100ul, 6 7 OHANA_BIG_ENDIAN = 0x00010203ul, 7 };8 }; 8 9 9 10 static const union { 10 unsigned char bytes[4];11 int value;11 unsigned char bytes[4]; 12 int value; 12 13 } ohana_host_order = { { 0, 1, 2, 3 } }; 13 14 … … 15 16 16 17 // we need to verify some type-related issues: 17 int main ( int argc, char **argv) {18 int main (void) { 18 19 19 int status;20 plan_tests (4); 20 21 21 status = 0;22 diag ("libohana typetest.c tests"); 22 23 23 // 1) have we defined BYTE_SWAP correctly? 24 int status = 0; 25 26 // 1) have we defined BYTE_SWAP correctly? 24 27 25 28 # ifdef BYTE_SWAP 26 if (OHANA_HOST_ORDER == OHANA_BIG_ENDIAN) { 27 fprintf (stderr, "ERROR: BYTE_SWAP is defined on a big endian machine\n"); 28 fprintf (stderr, "(see libohana/include/ohana.h)\n"); 29 status = 1; 30 } else { 31 fprintf (stderr, "BYTE_SWAP is small endian\n"); 32 } 29 ok (OHANA_HOST_ORDER == OHANA_LITTLE_ENDIAN, "BYTE_SWAP defined on small endian hardware (see libohana/include/ohana.h)"); 33 30 # else 34 if (OHANA_HOST_ORDER == OHANA_BIG_ENDIAN) { 35 fprintf (stderr, "NOT_BYTE_SWAP is big endian\n"); 36 } else { 37 fprintf (stderr, "ERROR: BYTE_SWAP not defined on a small endian machine\n"); 38 fprintf (stderr, "(see libohana/include/ohana.h)\n"); 39 status = 1; 40 } 31 ok (OHANA_HOST_ORDER == OHANA_BIG_ENDIAN, "BYTE_SWAP NOT defined on big endian hardware (see libohana/include/ohana.h)"); 41 32 # endif 42 33 43 // 2) have we defined NAN correctly?44 {45 float fvalue;46 double dvalue;34 // 2) have we defined NAN correctly? 35 { 36 float fvalue; 37 double dvalue; 47 38 48 fvalue = NAN;49 dvalue = NAN;39 fvalue = NAN; 40 dvalue = NAN; 50 41 51 if (isfinite(fvalue)) { 52 fprintf (stderr, "ERROR: NAN definition fails for float\n"); 53 fprintf (stderr, "fvalue: %e\n", fvalue); 54 status = 1; 55 } 56 if (isfinite(dvalue)) { 57 fprintf (stderr, "ERROR: NAN definition fails for double\n"); 58 fprintf (stderr, "dvalue: %e\n", dvalue); 59 status = 1; 60 } 61 62 fprintf (stderr, "fvalue: %e (isfinite: %d)\n", fvalue, isfinite(fvalue)); 63 fprintf (stderr, "dvalue: %e (isfinite: %d)\n", dvalue, isfinite(dvalue)); 42 ok (isnan(fvalue), "float NAN correctly defined"); 43 ok (isnan(dvalue), "double NAN correctly defined"); 64 44 65 45 # ifdef __STDC_VERSION__ 66 fprintf (stderr,"STDC_VERSION: %ld\n", __STDC_VERSION__);46 diag ("STDC_VERSION: %ld\n", __STDC_VERSION__); 67 47 # else 68 fprintf (stderr, "STDC_VERSION is not set\n");48 diag ("STDC_VERSION is not set"); 69 49 # endif 70 }50 } 71 51 72 // 3) have we defined OFF_T_FMT correctly?73 off_t big_value;52 // 3) have we defined OFF_T_FMT correctly? this test should actually raise a compile-time error 53 off_t big_value = 10; 74 54 75 big_value = 10; 76 fprintf (stderr, "this is a big int: "OFF_T_FMT" n'est pas?\n", big_value); 55 char line[80]; 56 status = snprintf (line, 80, "this is a big int: "OFF_T_FMT" n'est pas?", big_value); 57 // 1234567890123456789 0123456789012 58 ok (status == 32, "correctly formatted an off_t int with %d chars", status); 77 59 78 // we could move the % out of the FMT and allow constructions like this:79 // # define OFF_T_FMT "jd"80 // fprintf (stderr, "this is a big int: %06"OFF_T_FMT_ALT" n'est pas?\n", big_value);81 // still kind of ugly...60 // we could move the % out of the FMT and allow constructions like this: 61 // # define OFF_T_FMT "jd" 62 // fprintf (stderr, "this is a big int: %06"OFF_T_FMT_ALT" n'est pas?\n", big_value); 63 // still kind of ugly... 82 64 83 exit (status); 65 fprintf (stderr, "max float: %e\n", FLT_MAX); 66 fprintf (stderr, "max double: %e\n", DBL_MAX); 67 fprintf (stderr, "min float: %e\n", FLT_MIN); 68 fprintf (stderr, "min double: %e\n", DBL_MIN); 69 70 return exit_status(); 84 71 }
Note:
See TracChangeset
for help on using the changeset viewer.
