mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 #include "mbed.h"
elessair 0:f269e3021894 2 #include "test_env.h"
elessair 0:f269e3021894 3 #include <string.h>
elessair 0:f269e3021894 4
elessair 0:f269e3021894 5 #define BUFFER_SIZE 256
elessair 0:f269e3021894 6 #define CLEAN_BUFFER(BUFF) memset(BUFF, 0x00, BUFFER_SIZE)
elessair 0:f269e3021894 7
elessair 0:f269e3021894 8 #define NEGATIVE_INTEGERS -32768,-3214,-999,-100,-1,0,-1,-4231,-999,-4123,-32760,-99999
elessair 0:f269e3021894 9 #define POSITIVE_INTEGERS 32768,3214,999,100,1,0,1,4231,999,4123,32760,99999
elessair 0:f269e3021894 10 #define FLOATS 0.002,0.92430,15.91320,791.77368,6208.2,25719.4952,426815.982588,6429271.046,42468024.93,212006462.910
elessair 0:f269e3021894 11
elessair 0:f269e3021894 12
elessair 0:f269e3021894 13 int main()
elessair 0:f269e3021894 14 {
elessair 0:f269e3021894 15 char buffer[BUFFER_SIZE] = {0};
elessair 0:f269e3021894 16 bool result = true;
elessair 0:f269e3021894 17 bool cmp_result;
elessair 0:f269e3021894 18
elessair 0:f269e3021894 19 {
elessair 0:f269e3021894 20 CLEAN_BUFFER(buffer);
elessair 0:f269e3021894 21 sprintf(buffer, "%i %d %i %d %i %d %i %d %i %d %i %i", NEGATIVE_INTEGERS);
elessair 0:f269e3021894 22 cmp_result = TESTENV_STRCMP(buffer, "-32768 -3214 -999 -100 -1 0 -1 -4231 -999 -4123 -32760 -99999");
elessair 0:f269e3021894 23 printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
elessair 0:f269e3021894 24 result = result && cmp_result;
elessair 0:f269e3021894 25 }
elessair 0:f269e3021894 26
elessair 0:f269e3021894 27 {
elessair 0:f269e3021894 28 CLEAN_BUFFER(buffer);
elessair 0:f269e3021894 29 sprintf(buffer, "%u %d %u %d %u %d %u %d %u %d %u %d", POSITIVE_INTEGERS);
elessair 0:f269e3021894 30 cmp_result = TESTENV_STRCMP(buffer, "32768 3214 999 100 1 0 1 4231 999 4123 32760 99999");
elessair 0:f269e3021894 31 printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
elessair 0:f269e3021894 32 result = result && cmp_result;
elessair 0:f269e3021894 33 }
elessair 0:f269e3021894 34
elessair 0:f269e3021894 35 {
elessair 0:f269e3021894 36 CLEAN_BUFFER(buffer);
elessair 0:f269e3021894 37 sprintf(buffer, "%x %X %x %X %x %X %x %X %x %X %x %X", POSITIVE_INTEGERS);
elessair 0:f269e3021894 38 cmp_result = TESTENV_STRCMP(buffer, "8000 C8E 3e7 64 1 0 1 1087 3e7 101B 7ff8 1869F");
elessair 0:f269e3021894 39 printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
elessair 0:f269e3021894 40 result = result && cmp_result;
elessair 0:f269e3021894 41 }
elessair 0:f269e3021894 42
elessair 0:f269e3021894 43 {
elessair 0:f269e3021894 44 CLEAN_BUFFER(buffer);
elessair 0:f269e3021894 45 sprintf(buffer, "%f %f %f %f %f %f %f %f %f %f", FLOATS);
elessair 0:f269e3021894 46 cmp_result = TESTENV_STRCMP(buffer, "0.002000 0.924300 15.913200 791.773680 6208.200000 25719.495200 426815.982588 6429271.046000 42468024.930000 212006462.910000");
elessair 0:f269e3021894 47 printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
elessair 0:f269e3021894 48 result = result && cmp_result;
elessair 0:f269e3021894 49 }
elessair 0:f269e3021894 50
elessair 0:f269e3021894 51 {
elessair 0:f269e3021894 52 CLEAN_BUFFER(buffer);
elessair 0:f269e3021894 53 sprintf(buffer, "%g %g %g %g %g %g %g %g %g %g", FLOATS);
elessair 0:f269e3021894 54 cmp_result = TESTENV_STRCMP(buffer, "0.002 0.9243 15.9132 791.774 6208.2 25719.5 426816 6.42927e+006 4.2468e+007 2.12006e+008");
elessair 0:f269e3021894 55 cmp_result = cmp_result || TESTENV_STRCMP(buffer, "0.002 0.9243 15.9132 791.774 6208.2 25719.5 426816 6.42927e+06 4.2468e+07 2.12006e+08");
elessair 0:f269e3021894 56 printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
elessair 0:f269e3021894 57 result = result && cmp_result;
elessair 0:f269e3021894 58 }
elessair 0:f269e3021894 59
elessair 0:f269e3021894 60 {
elessair 0:f269e3021894 61 CLEAN_BUFFER(buffer);
elessair 0:f269e3021894 62 sprintf(buffer, "%e %E %e %E %e %E %e %E %e %E", FLOATS);
elessair 0:f269e3021894 63 cmp_result = TESTENV_STRCMP(buffer, "2.000000e-003 9.243000E-001 1.591320e+001 7.917737E+002 6.208200e+003 2.571950E+004 4.268160e+005 6.429271E+006 4.246802e+007 2.120065E+008");
elessair 0:f269e3021894 64 cmp_result = cmp_result || TESTENV_STRCMP(buffer, "2.000000e-03 9.243000E-01 1.591320e+01 7.917737E+02 6.208200e+03 2.571950E+04 4.268160e+05 6.429271E+06 4.246802e+07 2.120065E+08");
elessair 0:f269e3021894 65 printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
elessair 0:f269e3021894 66 result = result && cmp_result;
elessair 0:f269e3021894 67 }
elessair 0:f269e3021894 68
elessair 0:f269e3021894 69 {
elessair 0:f269e3021894 70 CLEAN_BUFFER(buffer);
elessair 0:f269e3021894 71 char str[] ="- This, a sample string.";
elessair 0:f269e3021894 72 char * pch = strtok (str," ,.-");
elessair 0:f269e3021894 73 while (pch != NULL) {
elessair 0:f269e3021894 74 strcat(buffer, pch);
elessair 0:f269e3021894 75 pch = strtok (NULL, " ,.-");
elessair 0:f269e3021894 76 }
elessair 0:f269e3021894 77 cmp_result = TESTENV_STRCMP(buffer, "Thisasamplestring");
elessair 0:f269e3021894 78 printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
elessair 0:f269e3021894 79 result = result && cmp_result;
elessair 0:f269e3021894 80 }
elessair 0:f269e3021894 81
elessair 0:f269e3021894 82 {
elessair 0:f269e3021894 83 CLEAN_BUFFER(buffer);
elessair 0:f269e3021894 84 char str[] = "This is a sample string";
elessair 0:f269e3021894 85 char key[] = "aeiou";
elessair 0:f269e3021894 86 char *pch = strpbrk(str, key);
elessair 0:f269e3021894 87 while (pch != NULL)
elessair 0:f269e3021894 88 {
elessair 0:f269e3021894 89 char buf[2] = {*pch, '\0'};
elessair 0:f269e3021894 90 strcat(buffer, buf);
elessair 0:f269e3021894 91 pch = strpbrk(pch + 1,key);
elessair 0:f269e3021894 92 }
elessair 0:f269e3021894 93 cmp_result = TESTENV_STRCMP(buffer, "iiaaei");
elessair 0:f269e3021894 94 printf("[%s] %s\r\n", cmp_result ? "OK" : "FAIL", buffer);
elessair 0:f269e3021894 95 result = result && cmp_result;
elessair 0:f269e3021894 96 }
elessair 0:f269e3021894 97
elessair 0:f269e3021894 98 notify_completion(result);
elessair 0:f269e3021894 99 return 0;
elessair 0:f269e3021894 100 }