]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/utest/general/general.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / tests / utest / general / general.cpp
1 #include "TestHarness.h"
2 #include <utility>
3 #include "mbed.h"
4
5 TEST_GROUP(Integer_Constant_Division)
6 {
7 uint32_t test_64(uint64_t ticks) {
8 ticks >>= 3; // divide by 8
9 if (ticks > 0xFFFFFFFF) {
10 ticks /= 3;
11 } else {
12 ticks = (ticks * 0x55555556) >> 32; // divide by 3
13 }
14 return (uint32_t)(0xFFFFFFFF & ticks);
15 }
16 };
17
18 // 0xFFFFFFFF * 8 = 0x7fffffff8
19 TEST(Integer_Constant_Division, Divide_By_8)
20 {
21 std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
22 uint32_t test_ret = test_64(values.second);
23 CHECK_EQUAL(values.first, test_ret);
24 }
25
26 // 0xFFFFFFFF * 24 = 0x17ffffffe8
27 TEST(Integer_Constant_Division, Divide_By_24)
28 {
29 std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
30 uint32_t test_ret = test_64(values.second);
31 CHECK_EQUAL(values.first, test_ret);
32 }
33
34 TEST_GROUP(RTC_Test)
35 {
36 char buffer[32];
37 const int CUSTOM_TIME = 1256729737;
38 };
39
40 TEST(RTC_Test, Check_Set_Time)
41 {
42 set_time(CUSTOM_TIME); // Set RTC time to Wed, 28 Oct 2009 11:35:37
43 time_t seconds = time(NULL);
44 strftime(buffer, 32, "%Y-%m-%d %H:%M:%S %p", localtime(&seconds));
45 STRCMP_EQUAL(buffer, "2009-10-28 11:35:37 AM");
46 }
47
48 TEST_GROUP(C_String_Format)
49 {
50 char buffer[256];
51 };
52
53 #define POSITIVE_INTEGERS 32768,3214,999,100,1,0,1,4231,999,4123,32760,99999
54 TEST(C_String_Format, Sprintf_Positive_Integers)
55 {
56 sprintf(buffer, "%u %d %u %d %u %d %u %d %u %d %u %d", POSITIVE_INTEGERS);
57 STRCMP_EQUAL(buffer, "32768 3214 999 100 1 0 1 4231 999 4123 32760 99999");
58 }
59
60 #define NEGATIVE_INTEGERS -32768,-3214,-999,-100,-1,0,-1,-4231,-999,-4123,-32760,-99999
61 TEST(C_String_Format, Sprintf_Negative_Integers)
62 {
63 sprintf(buffer, "%i %d %i %d %i %d %i %d %i %d %i %i", NEGATIVE_INTEGERS);
64 STRCMP_EQUAL(buffer, "-32768 -3214 -999 -100 -1 0 -1 -4231 -999 -4123 -32760 -99999");
65 }
66
67 #ifdef DEVICE_SEMIHOST
68 #include "semihost_api.h"
69
70 TEST_GROUP(Device_Semihost)
71 {
72 char uid[48];
73 };
74
75 TEST(Device_Semihost, semihost_connected)
76 {
77 CHECK(semihost_connected());
78 }
79
80 TEST(Device_Semihost, mbed_interface_connected)
81 {
82 CHECK(mbed_interface_connected());
83 }
84
85 TEST(Device_Semihost, mbed_interface_uid)
86 {
87 CHECK_EQUAL(mbed_interface_uid(uid), 0);
88 }
89
90 #endif
Imprint / Impressum