Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
2.0 KiB

  1. #include "unity_fixture.h"
  2. #include "../src/LedDriver.h"
  3. #include "../mocks/RuntimeErrorStub.h"
  4. TEST_GROUP(LedDriver);
  5. static uint16_t virtualLeds;
  6. TEST_SETUP(LedDriver) {
  7. LedDriver_Create(&virtualLeds);
  8. }
  9. TEST_TEAR_DOWN(LedDriver) {
  10. }
  11. TEST(LedDriver, LedsOffAfterCreate) {
  12. uint16_t virtualLeds = 0xFFFF;
  13. LedDriver_Create(&virtualLeds);
  14. TEST_ASSERT_EQUAL_HEX16(0x0000, virtualLeds);
  15. }
  16. TEST(LedDriver, TurnOnLedOne) {
  17. LedDriver_TurnOn(1);
  18. TEST_ASSERT_EQUAL_HEX16(0x0001, virtualLeds);
  19. }
  20. TEST(LedDriver, TurnOffLedOne) {
  21. LedDriver_TurnOn(1);
  22. LedDriver_TurnOff(1);
  23. TEST_ASSERT_EQUAL_HEX16(0x0000, virtualLeds);
  24. }
  25. TEST(LedDriver, TurnOnMultipleLeds) {
  26. LedDriver_TurnOn(8);
  27. LedDriver_TurnOn(9);
  28. TEST_ASSERT_EQUAL_HEX16(0x0180, virtualLeds);
  29. }
  30. TEST(LedDriver, TurnAllOn) {
  31. LedDriver_TurnAllOn();
  32. TEST_ASSERT_EQUAL_HEX16(0xFFFF, virtualLeds);
  33. }
  34. TEST(LedDriver, TurnOffAnyLed) {
  35. LedDriver_TurnAllOn();
  36. LedDriver_TurnOff(8);
  37. TEST_ASSERT_EQUAL_HEX16(0xFF7F, virtualLeds);
  38. }
  39. TEST(LedDriver, LedMemoryIsNotReadable) {
  40. virtualLeds = 0xFFFF;
  41. LedDriver_TurnOn(8);
  42. TEST_ASSERT_EQUAL_HEX16(0x0080, virtualLeds);
  43. }
  44. TEST(LedDriver, UpperAndLowerBounds) {
  45. LedDriver_TurnOn(1);
  46. LedDriver_TurnOn(16);
  47. TEST_ASSERT_EQUAL_HEX16(0x8001, virtualLeds);
  48. }
  49. TEST(LedDriver, OutOfBoundsTurnOnDoesNotHarm) {
  50. LedDriver_TurnOn(-1);
  51. LedDriver_TurnOn(0);
  52. LedDriver_TurnOn(17);
  53. LedDriver_TurnOn(3141);
  54. TEST_ASSERT_EQUAL_HEX16(0x0000, virtualLeds);
  55. }
  56. TEST(LedDriver, OutOfBoundsTurnOffDoesNotHarm) {
  57. LedDriver_TurnAllOn();
  58. LedDriver_TurnOff(-1);
  59. LedDriver_TurnOff(0);
  60. LedDriver_TurnOff(17);
  61. LedDriver_TurnOff(3141);
  62. TEST_ASSERT_EQUAL_HEX16(0xFFFF, virtualLeds);
  63. }
  64. TEST(LedDriver, OutOfBoundsProducesRuntimeError) {
  65. LedDriver_TurnOn(-1);
  66. TEST_ASSERT_EQUAL_STRING("LED Driver: out-of-bounds LED", RuntimeErrorStub_GetLastError());
  67. TEST_ASSERT_EQUAL(-1, RuntimeErrorStub_GetLastParameter());
  68. }
  69. IGNORE_TEST(LedDriver, OutOfBoundsToDo) {
  70. /* TODO: what should we do during runtime? */
  71. }