Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
general.cpp
00001 #include "TestHarness.h" 00002 #include <utility> 00003 #include "mbed.h" 00004 00005 TEST_GROUP(Integer_Constant_Division) 00006 { 00007 uint32_t test_64(uint64_t ticks) { 00008 ticks >>= 3; // divide by 8 00009 if (ticks > 0xFFFFFFFF) { 00010 ticks /= 3; 00011 } else { 00012 ticks = (ticks * 0x55555556) >> 32; // divide by 3 00013 } 00014 return (uint32_t)(0xFFFFFFFF & ticks); 00015 } 00016 }; 00017 00018 // 0xFFFFFFFF * 8 = 0x7fffffff8 00019 TEST(Integer_Constant_Division, Divide_By_8) 00020 { 00021 std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8); 00022 uint32_t test_ret = test_64(values.second); 00023 CHECK_EQUAL(values.first, test_ret); 00024 } 00025 00026 // 0xFFFFFFFF * 24 = 0x17ffffffe8 00027 TEST(Integer_Constant_Division, Divide_By_24) 00028 { 00029 std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8); 00030 uint32_t test_ret = test_64(values.second); 00031 CHECK_EQUAL(values.first, test_ret); 00032 } 00033 00034 TEST_GROUP(RTC_Test) 00035 { 00036 char buffer[32]; 00037 const int CUSTOM_TIME = 1256729737; 00038 }; 00039 00040 TEST(RTC_Test, Check_Set_Time) 00041 { 00042 set_time(CUSTOM_TIME); // Set RTC time to Wed, 28 Oct 2009 11:35:37 00043 time_t seconds = time(NULL); 00044 strftime(buffer, 32, "%Y-%m-%d %H:%M:%S %p", localtime(&seconds)); 00045 STRCMP_EQUAL(buffer, "2009-10-28 11:35:37 AM"); 00046 } 00047 00048 TEST_GROUP(C_String_Format) 00049 { 00050 char buffer[256]; 00051 }; 00052 00053 #define POSITIVE_INTEGERS 32768,3214,999,100,1,0,1,4231,999,4123,32760,99999 00054 TEST(C_String_Format, Sprintf_Positive_Integers) 00055 { 00056 sprintf(buffer, "%u %d %u %d %u %d %u %d %u %d %u %d", POSITIVE_INTEGERS); 00057 STRCMP_EQUAL(buffer, "32768 3214 999 100 1 0 1 4231 999 4123 32760 99999"); 00058 } 00059 00060 #define NEGATIVE_INTEGERS -32768,-3214,-999,-100,-1,0,-1,-4231,-999,-4123,-32760,-99999 00061 TEST(C_String_Format, Sprintf_Negative_Integers) 00062 { 00063 sprintf(buffer, "%i %d %i %d %i %d %i %d %i %d %i %i", NEGATIVE_INTEGERS); 00064 STRCMP_EQUAL(buffer, "-32768 -3214 -999 -100 -1 0 -1 -4231 -999 -4123 -32760 -99999"); 00065 } 00066 00067 #ifdef DEVICE_SEMIHOST 00068 #include "semihost_api.h" 00069 00070 TEST_GROUP(Device_Semihost) 00071 { 00072 char uid[48]; 00073 }; 00074 00075 TEST(Device_Semihost, semihost_connected) 00076 { 00077 CHECK(semihost_connected()); 00078 } 00079 00080 TEST(Device_Semihost, mbed_interface_connected) 00081 { 00082 CHECK(mbed_interface_connected()); 00083 } 00084 00085 TEST(Device_Semihost, mbed_interface_uid) 00086 { 00087 CHECK_EQUAL(mbed_interface_uid(uid), 0); 00088 } 00089 00090 #endif
Generated on Tue Jul 12 2022 11:02:38 by
