Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Nov 24, 2023
1 parent e2893b0 commit 0c0e7c4
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 18 deletions.
22 changes: 16 additions & 6 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ unittest(test_new_operator)
assertEqualINF(exp(800));
assertEqualINF(0.0/0.0);
assertEqualINF(42);
assertEqualNAN(INFINITY - INFINITY);
assertEqualNAN(0.0/0.0);
assertEqualNAN(42);
Expand All @@ -63,7 +63,7 @@ unittest(test_new_operator)
unittest(test_constructor)
{
Wire.resetMocks();

Wire.begin();
I2C_eeprom EE(0x50, 0x8000);

assertTrue(EE.begin());
Expand All @@ -76,6 +76,8 @@ unittest(test_constructor)

unittest(test_constants)
{
Wire.resetMocks();
Wire.begin();
I2C_eeprom EE(0x50, 0x8000);

assertEqual(I2C_DEVICESIZE_24LC512, 65536);
Expand All @@ -93,6 +95,8 @@ unittest(test_constants)

unittest(test_getPageSize)
{
Wire.resetMocks();
Wire.begin();
I2C_eeprom EE(0x50, 0x8000);

assertEqual(EE.getPageSize(I2C_DEVICESIZE_24LC512), 128);
Expand All @@ -105,7 +109,7 @@ unittest(test_getPageSize)
assertEqual(EE.getPageSize(I2C_DEVICESIZE_24LC04), 16);
assertEqual(EE.getPageSize(I2C_DEVICESIZE_24LC02), 8);
assertEqual(EE.getPageSize(I2C_DEVICESIZE_24LC01), 8);

I2C_eeprom prom(0x50, 0x8123);
assertEqual(prom.getDeviceSize(), 0x8000);
assertEqual(prom.getPageSize(), 64);
Expand All @@ -114,6 +118,8 @@ unittest(test_getPageSize)

unittest(test_setDeviceSize)
{
Wire.resetMocks();
Wire.begin();
I2C_eeprom EE(0x50, 0x8000);

assertEqual(EE.setDeviceSize(I2C_DEVICESIZE_24LC512), I2C_DEVICESIZE_24LC512);
Expand All @@ -140,9 +146,11 @@ unittest(test_setDeviceSize)

}

/*

unittest(test_setPageSize)
{
Wire.resetMocks();
Wire.begin();
I2C_eeprom EE(0x50, 0x8000);

assertEqual(EE.setPageSize(129), 128);
Expand All @@ -159,8 +167,10 @@ unittest(test_setPageSize)
assertEqual(EE.setPageSize(9), 8);
assertEqual(EE.setPageSize(8), 8);
}
*/


unittest_main()

// --------

// -- END OF FILE --

41 changes: 31 additions & 10 deletions test/unit_test_cyclic_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
// Note: The implementation of the I2C_eeprom_cyclic_store should have been
// made injactable so that a mock or fake for I2C_eeprom could have been used
// instead of having to rely on a test implementation of the Wire singleton.
//
//
// This could have been done by changing the class to take two template
// parameters, the first being one for I2C_eeprom or it's mock and the second
// being the data type to store. For simplicity an alias could have been
// introduced so that users wouldn't have to specify I2C_eeprom but that made
// the editor lose track of the intellisense comments. :-/
// the editor lose track of the intellisense comments. :-/
//
// Thus this remains until someone comes up with a brighter idea.

Expand All @@ -40,12 +40,13 @@ unittest_teardown()
}

/**
* Verify that I2C_eeprom_cyclic_store fails to
* Verify that I2C_eeprom_cyclic_store fails to
* initialize when unable to read from eeprom.
*/
unittest(cyclic_store_fails_begin)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand All @@ -57,12 +58,13 @@ unittest(cyclic_store_fails_begin)
}

/**
* Verify that I2C_eeprom_cyclic_store successfully
* Verify that I2C_eeprom_cyclic_store successfully
* initializes on empty eeprom.
*/
unittest(cyclic_store_empty_begin)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand All @@ -87,6 +89,7 @@ unittest(cyclic_store_empty_begin)
unittest(cyclic_store_double_page_buffer)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -117,6 +120,7 @@ unittest(cyclic_store_double_page_buffer)
unittest(cyclic_store_finds_single_stored_version)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -155,6 +159,7 @@ unittest(cyclic_store_finds_single_stored_version)
unittest(cyclic_store_finds_last_half_filled_eeprom)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -205,6 +210,7 @@ unittest(cyclic_store_finds_last_half_filled_eeprom)
unittest(cyclic_store_finds_version_if_last_slot)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -256,6 +262,7 @@ unittest(cyclic_store_finds_version_if_last_slot)
unittest(cyclic_store_finds_last_wrapped_eeprom)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -304,12 +311,13 @@ unittest(cyclic_store_finds_last_wrapped_eeprom)
* Verify that I2C_eeprom_cyclic_store successfully finds the last
* entry after writes have wrapped around the end of the eeprom
* when using a buffer that spans two pages. And that it does so
* even if the number of pages is not evenly divisable by the
* even if the number of pages is not evenly divisable by the
* number of pages the buffer span.
*/
unittest(cyclic_store_finds_last_wrapped_eeprom_double_page_buffer)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -361,6 +369,7 @@ unittest(cyclic_store_finds_last_wrapped_eeprom_double_page_buffer)
unittest(cyclic_store_fails_init_on_too_large_buffer)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE);
EE.begin();
Expand All @@ -376,6 +385,7 @@ unittest(cyclic_store_fails_init_on_too_large_buffer)
unittest(cyclic_store_empty_metrics)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -407,6 +417,7 @@ unittest(cyclic_store_empty_metrics)
unittest(cyclic_store_fails_metrics_when_failed_initialize)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE);
EE.begin();
Expand All @@ -427,6 +438,7 @@ unittest(cyclic_store_fails_metrics_when_failed_initialize)
unittest(cyclic_store_fails_metrics_when_not_initialized)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE);
EE.begin();
Expand All @@ -440,13 +452,14 @@ unittest(cyclic_store_fails_metrics_when_not_initialized)
}

/**
* Verify that I2C_eeprom_cyclic_store correctly
* Verify that I2C_eeprom_cyclic_store correctly
* increments the number of writes when saving
* new versions.
*/
unittest(cyclic_store_increments_write_counter)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -489,6 +502,7 @@ unittest(cyclic_store_increments_write_counter)
unittest(cyclic_store_format_single_page)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -522,6 +536,7 @@ unittest(cyclic_store_format_single_page)
unittest(cyclic_store_format_double_page)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -556,6 +571,7 @@ unittest(cyclic_store_format_double_page)
unittest(cyclic_store_format_double_page_odd_space)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

Expand Down Expand Up @@ -590,12 +606,13 @@ unittest(cyclic_store_format_double_page_odd_space)
unittest(cyclic_store_wrapping_single_page)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE);
EE.begin();

auto miso = Wire.getMiso(I2C_EEPROM_ADDR);
miso->push_back(0xff);
miso->push_back(0xff);
Expand Down Expand Up @@ -635,12 +652,13 @@ unittest(cyclic_store_wrapping_single_page)
unittest(cyclic_store_wrapping_double_page)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE);
EE.begin();

auto miso = Wire.getMiso(I2C_EEPROM_ADDR);
miso->push_back(0xff);
miso->push_back(0xff);
Expand Down Expand Up @@ -677,12 +695,13 @@ unittest(cyclic_store_wrapping_double_page)
unittest(cyclic_store_wrapping_double_page_odd_space)
{
Wire.resetMocks();
Wire.begin();

auto mosi = Wire.getMosi(I2C_EEPROM_ADDR);

I2C_eeprom EE(I2C_EEPROM_ADDR, I2C_EEPROM_SIZE);
EE.begin();

auto miso = Wire.getMiso(I2C_EEPROM_ADDR);
miso->push_back(0xff);
miso->push_back(0xff);
Expand Down Expand Up @@ -713,4 +732,6 @@ unittest(cyclic_store_wrapping_double_page_odd_space)

unittest_main()

// --------

// -- END OF FILE --

16 changes: 14 additions & 2 deletions test/unit_test_page_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ unittest_teardown()
/**
* Verify that an instance gets the default page size
* when the constructor without device size is used.
* The expected outcome is I2C_EEPROM_PAGESIZE
* The expected outcome is I2C_EEPROM_PAGESIZE
*/
unittest(i2c_eeprom_default_page_size)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom eeprom(I2C_EEPROM_ADDR);

Expand All @@ -61,6 +62,7 @@ unittest(i2c_eeprom_default_page_size)
unittest(i2c_eeprom_1k_page_size)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x80);

Expand All @@ -76,6 +78,7 @@ unittest(i2c_eeprom_1k_page_size)
unittest(i2c_eeprom_2k_page_size)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x100);

Expand All @@ -91,6 +94,7 @@ unittest(i2c_eeprom_2k_page_size)
unittest(i2c_eeprom_4k_page_size)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x200);

Expand All @@ -106,6 +110,7 @@ unittest(i2c_eeprom_4k_page_size)
unittest(i2c_eeprom_8k_page_size)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x400);

Expand All @@ -121,6 +126,7 @@ unittest(i2c_eeprom_8k_page_size)
unittest(i2c_eeprom_16k_page_size)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x800);

Expand All @@ -136,6 +142,7 @@ unittest(i2c_eeprom_16k_page_size)
unittest(i2c_eeprom_32k_page_size)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x1000);

Expand All @@ -151,6 +158,7 @@ unittest(i2c_eeprom_32k_page_size)
unittest(i2c_eeprom_64k_page_size)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x2000);

Expand All @@ -166,6 +174,7 @@ unittest(i2c_eeprom_64k_page_size)
unittest(i2c_eeprom_128k_page_size)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x4000);

Expand All @@ -181,6 +190,7 @@ unittest(i2c_eeprom_128k_page_size)
unittest(i2c_eeprom_256k_page_size)
{
Wire.resetMocks();
Wire.begin();

I2C_eeprom eeprom(I2C_EEPROM_ADDR, 0x8000);

Expand All @@ -191,4 +201,6 @@ unittest(i2c_eeprom_256k_page_size)

unittest_main()

// ------------------

// -- END OF FILE --

0 comments on commit 0c0e7c4

Please sign in to comment.