?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. /*
  2. Permission to use, copy, modify, and/or distribute this software for any purpose
  3. with or without fee is hereby granted.
  4.  
  5. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  6. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  7. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  8. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
  9. OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  10. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  11. OF THIS SOFTWARE.
  12. */
  13.  
  14. #ifdef ADD_UNIT_TESTS
  15.  
  16. #include "../sjasm/sjdefs.h"
  17. #include "UnitTest++/UnitTest++.h"
  18.  
  19. class DeviceFixture {
  20. public:
  21.         CDevice testDev;        // test device: two 0x4000 slots, three pages
  22.  
  23.         DeviceFixture() : testDev("TESTDEV", nullptr) {
  24.                 testDev.AddSlot(0, 0x4000);
  25.                 testDev.AddSlot(0x4000, 0x4000);
  26.                 testDev.Memory = new byte[0x4000 * 3]();
  27.                 testDev.AddPage(testDev.Memory, 0x4000);
  28.                 testDev.AddPage(testDev.Memory+0x4000, 0x4000);
  29.                 testDev.AddPage(testDev.Memory+0x8000, 0x4000);
  30.                 testDev.GetSlot(0)->Page = testDev.GetPage(0);
  31.                 testDev.GetSlot(1)->Page = testDev.GetPage(1);
  32.                 testDev.SetSlot(0);
  33.         }
  34. };
  35.  
  36. TEST_FIXTURE(DeviceFixture, Device_GetInvalidSlot) {
  37.         pass = 0;       // inhibit error output from GetSlot
  38.         CHECK(testDev.GetSlot(0) != testDev.GetSlot(1));        // sanity check
  39.         CHECK(testDev.GetSlot(0) == testDev.GetSlot(2));        // actual test
  40. }
  41.  
  42. TEST_FIXTURE(DeviceFixture, Device_GetInvalidPage) {
  43.         pass = 0;       // inhibit error output from GetSlot
  44.         CHECK(testDev.GetPage(0) != testDev.GetPage(2));        // sanity check
  45.         CHECK(testDev.GetPage(0) == testDev.GetPage(3));        // actual test
  46. }
  47.  
  48. TEST_FIXTURE(DeviceFixture, Device_GetSlotOfA16) {
  49.         CHECK(-1 == testDev.GetSlotOfA16(0x8000));
  50.         CHECK(-1 == testDev.GetSlotOfA16(-1));
  51.         CHECK(0 == testDev.GetSlotOfA16(0x0123));
  52.         CHECK(1 == testDev.GetSlotOfA16(0x4123));
  53. }
  54.  
  55. TEST_FIXTURE(DeviceFixture, Device_GetPageOfA16) {
  56.         CHECK(-1 == testDev.GetPageOfA16(0x8000));
  57.         CHECK(-1 == testDev.GetPageOfA16(-1));
  58.         CHECK(0 == testDev.GetPageOfA16(0x0123));
  59.         CHECK(1 == testDev.GetPageOfA16(0x4123));
  60. }
  61.  
  62. #endif
  63.