forked from Arduino-CI/arduino_ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstdlib.cpp
46 lines (40 loc) · 1.13 KB
/
stdlib.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <ArduinoUnitTests.h>
#include <Arduino.h>
#define ARRAY_SIZEOF(a) ( sizeof(a) / sizeof((a)[0]) )
unittest(library_tests_itoa)
{
char buf[32];
const char *result;
struct {
int value;
const char *expected;
int base;
} table[] = {
{ 54325, "1101010000110101", 2 },
{ 54325, "54325", 10 },
{ 54325, "D435", 16 },
{ 493, "755", 8 },
{ -1, "-1", 10 },
{ 32767, "32767", 10},
{ 32767, "7FFF", 16},
{ 65535, "65535", 10},
{ 65535, "FFFF", 16},
{ 2147483647, "2147483647", 10},
{ 2147483647, "7FFFFFFF", 16},
};
for (int i = 0; i < ARRAY_SIZEOF(table); i++) {
result = itoa(table[i].value, buf, table[i].base);
assertEqual(table[i].expected, result);
}
// While only bases 2, 8, 10 and 16 are of real interest, lets test that all
// bases at least produce expected output for a few test points simple to test.
for (int base = 2; base <= 16; base++) {
result = itoa(0, buf, base);
assertEqual("0", result);
result = itoa(1, buf, base);
assertEqual("1", result);
result = itoa(base, buf, base);
assertEqual("10", result);
}
}
unittest_main()