libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
pcf8523.test.h
Go to the documentation of this file.
1 #include "unity.h"
2 #include "c++-alloc.h"
3 #include "pcf8523.h"
4 
5 //TODO(SRLM): Get rid of the hardcoded pins.
6 const int kPIN_I2C_SCL = 0;
7 const int kPIN_I2C_SDA = 1;
8 
10 I2C * bus;
11 
12 
14 
15 class UnityTests {
16 public:
17 
18  static void setUp(void) {
19  bus = new I2C;
21  sut = new PCF8523();
22  sut->Init(bus);
23  }
24 
25  static void tearDown(void) {
26  delete bus;
27  delete sut;
28  }
29 
30  static void test_SaveCurrentClock(void) {
31  //Saves the current clock so that we don't have to keep putting the time back in.
32  //It's ok if it get's off by a second or two.
34  TEST_IGNORE();
35  }
36 
37  static void test_GetStatusPass(void) {
38  TEST_ASSERT_TRUE(sut->GetStatus());
39  }
40 
41  static void test_ConvertToBCDUnitsOnly(void) {
42  TEST_ASSERT_EQUAL_HEX8(0b00000010, sut->ConvertToBCD(2));
43  }
44 
45  static void test_ConvertToBCDTensOnly(void) {
46  TEST_ASSERT_EQUAL_HEX8(0b01010000, sut->ConvertToBCD(50));
47  }
48 
49  static void test_ConvertToBCDBothUnitsAndTens(void) {
50  TEST_ASSERT_EQUAL_HEX8(0b01001001, sut->ConvertToBCD(49));
51  }
52 
53  static void test_ConvertFromBCDUnitsOnly(void) {
54  TEST_ASSERT_EQUAL_INT(2, sut->ConvertFromBCD(0b00000010));
55  }
56 
57  static void test_ConvertFromBCDTensOnly(void) {
58  TEST_ASSERT_EQUAL_INT(50, sut->ConvertFromBCD(0b01010000));
59  }
60 
61  static void test_ConvertFromBCDUnitsAndTens(void) {
62  TEST_ASSERT_EQUAL_INT(49, sut->ConvertFromBCD(0b01001001));
63  }
64 
65  static void test_SetGetClock(void) {
66 
67  int clock[] = {12, 1, 24, 13, 59, 12, 4};
68  int result[7];
69  TEST_ASSERT_TRUE(sut->SetClock(clock[0], clock[1], clock[2], clock[3], clock[4], clock[5], clock[6]));
70  TEST_ASSERT_TRUE(sut->GetClock(result[0], result[1], result[2], result[3], result[4], result[5], result[6]));
71 
72  TEST_ASSERT_EQUAL_INT_ARRAY(clock, result, 7);
73 
74  }
75 
76  static void test_SetGetClockNoWeekday(void) {
77 
78  int clock[] = {12, 1, 24, 13, 59, 12};
79  int result[7];
80  TEST_ASSERT_TRUE(sut->SetClock(clock[0], clock[1], clock[2], clock[3], clock[4], clock[5]));
81  TEST_ASSERT_TRUE(sut->GetClock(result[0], result[1], result[2], result[3], result[4], result[5]));
82 
83  TEST_ASSERT_EQUAL_INT_ARRAY(clock, result, 6);
84 
85 
86  }
87 
88  static void test_ClockCountsSeconds(void) {
89  int clock[] = {12, 1, 24, 13, 59, 12};
90  int result[7];
91  TEST_ASSERT_TRUE(sut->SetClock(clock[0], clock[1], clock[2], clock[3], clock[4], clock[5]));
92 
93  const int secondsDelay = 2;
94  waitcnt(CLKFREQ * secondsDelay + CNT);
95  clock[5] += secondsDelay;
96  TEST_ASSERT_TRUE(sut->GetClock(result[0], result[1], result[2], result[3], result[4], result[5]));
97  TEST_ASSERT_EQUAL_INT_ARRAY(clock, result, 6);
98 
99 
100  }
101 
102  static void test_RestoreCurrentClock(void) {
104  TEST_IGNORE();
105  }
106 
107  static void test_GetStatusIsFalseForNoBus(void) {
108  PCF8523 dummy;
109  TEST_ASSERT_FALSE(dummy.GetStatus());
110  }
111 };
112 
113