|
| 1 | +/* |
| 2 | + test_pgmspace.cpp - pgmspace tests |
| 3 | + Copyright © 2016 Ivan Grokhotkov |
| 4 | +
|
| 5 | + Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | + of this software and associated documentation files (the "Software"), to deal |
| 7 | + in the Software without restriction, including without limitation the rights |
| 8 | + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | + copies of the Software, and to permit persons to whom the Software is |
| 10 | + furnished to do so, subject to the following conditions: |
| 11 | +
|
| 12 | + The above copyright notice and this permission notice shall be included in |
| 13 | + all copies or substantial portions of the Software. |
| 14 | + */ |
| 15 | + |
| 16 | +#include <catch.hpp> |
| 17 | +#include <string.h> |
| 18 | +#include <FS.h> |
| 19 | +#include "../common/spiffs_mock.h" |
| 20 | +#include <spiffs/spiffs.h> |
| 21 | + |
| 22 | +// Use a SPIFFS file because we can't instantiate a virtual class like Print |
| 23 | +TEST_CASE("Print::write overrides all compile properly", "[core][Print]") |
| 24 | +{ |
| 25 | + SPIFFS_MOCK_DECLARE(64, 8, 512, ""); |
| 26 | + REQUIRE(SPIFFS.begin()); |
| 27 | + auto p = SPIFFS.open("test.bin", "w"); |
| 28 | + REQUIRE(p); |
| 29 | + uint8_t uint8 = 1; |
| 30 | + uint16_t uint16 = 2; |
| 31 | + uint32_t uint32 = 3; |
| 32 | + size_t size = 4; |
| 33 | + int8_t int8 = 1; |
| 34 | + int16_t int16 = 2; |
| 35 | + int32_t int32 = 3; |
| 36 | + char c = 'h'; |
| 37 | + int i = 10; |
| 38 | + long l = 11; |
| 39 | + unsigned char uc = 20; |
| 40 | + unsigned int ui = 21; |
| 41 | + unsigned long ul = 22; |
| 42 | + p.write(uint8); |
| 43 | + p.write(uint16); |
| 44 | + p.write(uint32); |
| 45 | + p.write(size); |
| 46 | + p.write(int8); |
| 47 | + p.write(int16); |
| 48 | + p.write(int32); |
| 49 | + p.write(c); |
| 50 | + p.write(i); |
| 51 | + p.write(l); |
| 52 | + p.write(uc); |
| 53 | + p.write(ui); |
| 54 | + p.write(ul); |
| 55 | + p.write(0); |
| 56 | + p.write(1); |
| 57 | + p.close(); |
| 58 | + |
| 59 | + p = SPIFFS.open("test.bin", "r"); |
| 60 | + REQUIRE(p); |
| 61 | + uint8_t buff[16]; |
| 62 | + int len = p.read(buff, 16); |
| 63 | + p.close(); |
| 64 | + REQUIRE(len == 15); |
| 65 | + REQUIRE(buff[0] == 1); |
| 66 | + REQUIRE(buff[1] == 2); |
| 67 | + REQUIRE(buff[2] == 3); |
| 68 | + REQUIRE(buff[3] == 4); |
| 69 | + REQUIRE(buff[4] == 1); |
| 70 | + REQUIRE(buff[5] == 2); |
| 71 | + REQUIRE(buff[6] == 3); |
| 72 | + REQUIRE(buff[7] == 'h'); |
| 73 | + REQUIRE(buff[8] == 10); |
| 74 | + REQUIRE(buff[9] == 11); |
| 75 | + REQUIRE(buff[10] == 20); |
| 76 | + REQUIRE(buff[11] == 21); |
| 77 | + REQUIRE(buff[12] == 22); |
| 78 | + REQUIRE(buff[13] == 0); |
| 79 | + REQUIRE(buff[14] == 1); |
| 80 | +} |
0 commit comments