general.cpp 2.2 KB

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