libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
eeprom.test.h
Go to the documentation of this file.
1 #include <stdio.h>
2 #include "unity.h"
3 #include "eeprom.h"
4 
5 
6 //TODO: Add test to see about the -1 return value for Get
7 
8 //offset is a randomization feature to make sure that we're not reading from a
9 //previous successful test (and pass, even if the Put failed).
10 //Offset is based on the current seconds at compilation.
11 int addressOffset = ((__TIME__)[6] - '0')*10 + (__TIME__)[7] - '0';
12 char dataOffset = ((__TIME__)[3] - '0')*5 + (__TIME__)[7] - '0';
13 
14 class UnityTests {
15 public:
16 
17  static void setUp(void) {
18 
19  }
20 
21  static void tearDown(void) {
22 
23  }
24 
25  static void test_Warning(void) {
26  printf("---------------------------------------------\r\n");
27  printf("Warning: This test suite mangles your EEPROM!\r\n");
28  //Warning: Tests hang if the following %i code is included in LMM mode, at least if the executable is too large
29  //#ifdef __PROPELLER_CMM__
30  printf("Current addressOffset: %i\r\n", addressOffset);
31  printf("Current dataOffset: %i\r\n", dataOffset);
32  //#endif
33  printf("---------------------------------------------\r\n");
34  }
35 
36  static void test_SingleByteReadWrite(void) {
37  EEPROM mem;
38  mem.Init();
39  unsigned short address = 0x8121 + addressOffset;
40  char data = 0xA9 + dataOffset;
41  TEST_ASSERT_TRUE(mem.Put(address, data));
42  TEST_ASSERT_EQUAL_HEX8(data, mem.Get(address));
43  }
44 
45  // This test had a single failure on 2013-04-11:
46  // eeprom.test.cpp:40:test_SingleByteReadWrite:FAIL: Expected 0xB5 Was 0x00
47  // Mode: LMM
48 
49  // eeprom.test.cpp:40:test_SingleByteReadWrite:FAIL: Expected 0xBD Was 0x13
50  // Current addressOffset: 5
51  // Current dataOffset: 20
52  // Mode: LMM
53 
54  // PASS
55  // Current addressOffset: 53
56  // Current dataOffset: 18
57  // Mode: LMM
58 
59  // PASS
60  // Current addressOffset: 7
61  // Current dataOffset: 27
62  // Mode: LMM
63 
64  static void test_PageWriteSingleByteRead(void) {
65  EEPROM mem;
66  mem.Init();
67  unsigned short address = 0x80F5 + addressOffset;
68  int size = 500;
69  char data [size];
70  char result = dataOffset;
71  data[0] = result;
72  data[size - 1] = result;
73  TEST_ASSERT_TRUE(mem.Put(address, data, size));
74  TEST_ASSERT_EQUAL_INT(result, mem.Get(address));
75  TEST_ASSERT_EQUAL_INT(result, mem.Get(address + size - 1));
76  }
77 
78  static void test_PageReadWrite(void) {
79  EEPROM mem;
80  mem.Init();
81  unsigned short address = 0x80F7 + addressOffset;
82  int size = 500;
83  char output [size];
84  char input [size];
85 
86  output[0] = 0x25 + dataOffset;
87  output[1] = 0xE9 + dataOffset;
88  output[size / 2] = 0x42 + dataOffset;
89  output[size - 1] = 0xF0 + dataOffset;
90 
91 
92  TEST_ASSERT_TRUE(mem.Put(address, output, size));
93  mem.Get(address, input, size);
94  TEST_ASSERT_EQUAL_MEMORY(output, input, size);
95 
96  }
97 
98  static void test_PageReadDoesntBufferOverflow(void) {
99  EEPROM mem;
100  mem.Init();
101  unsigned short address = 0x8223 + addressOffset;
102  int size = 200;
103  char output [size];
104  char input [size * 2];
105  char overflowPattern [size];
106  for (int i = 0; i < size; ++i) {
107  input[i + size] = overflowPattern[i] = 0x83 + dataOffset;
108  }
109 
110  mem.Put(address, output, size);
111  mem.Get(address, input, size);
112  TEST_ASSERT_EQUAL_MEMORY(overflowPattern, input + size, size);
113  }
114 
115  static void test_PutGetInt(void) {
116  EEPROM mem;
117  mem.Init();
118  unsigned short address = 0x9B21 + addressOffset;
119  int size = 4;
120  int bytes = 5367 + dataOffset;
121 
122  mem.PutNumber(address, bytes, size);
123  TEST_ASSERT_EQUAL_INT(bytes, mem.GetNumber(address, size));
124 
125  }
126 
127  static void test_PutGetShort(void) {
128  EEPROM mem;
129  mem.Init();
130  unsigned short address = 0x965D + addressOffset;
131  int size = 2;
132  int bytes = 525 + dataOffset;
133 
134  mem.PutNumber(address, bytes, size);
135  TEST_ASSERT_EQUAL_INT(bytes, mem.GetNumber(address, size));
136  }
137 
138 };
139 
140