Line | |
---|
1 | // Copyright Benoit Blanchon 2014-2016
|
---|
2 | // MIT License
|
---|
3 | //
|
---|
4 | // Arduino JSON library
|
---|
5 | // https://github.com/bblanchon/ArduinoJson
|
---|
6 | // If you like this project, please add a star!
|
---|
7 |
|
---|
8 | #include <gtest/gtest.h>
|
---|
9 | #include <ArduinoJson/Internals/StaticStringBuilder.hpp>
|
---|
10 |
|
---|
11 | using namespace ArduinoJson::Internals;
|
---|
12 |
|
---|
13 | class StringBuilderTests : public testing::Test {
|
---|
14 | protected:
|
---|
15 | virtual void SetUp() {
|
---|
16 | _stringBuilder = new StaticStringBuilder(_buffer, sizeof(_buffer));
|
---|
17 | }
|
---|
18 |
|
---|
19 | virtual void TearDown() { delete _stringBuilder; }
|
---|
20 |
|
---|
21 | void print(const char *value) { _returnValue = _stringBuilder->print(value); }
|
---|
22 |
|
---|
23 | void outputMustBe(const char *expected) { EXPECT_STREQ(expected, _buffer); }
|
---|
24 |
|
---|
25 | void resultMustBe(size_t expected) { EXPECT_EQ(expected, _returnValue); }
|
---|
26 |
|
---|
27 | private:
|
---|
28 | char _buffer[20];
|
---|
29 | Print *_stringBuilder;
|
---|
30 | size_t _returnValue;
|
---|
31 | };
|
---|
32 |
|
---|
33 | TEST_F(StringBuilderTests, InitialState) { outputMustBe(""); }
|
---|
34 |
|
---|
35 | TEST_F(StringBuilderTests, OverCapacity) {
|
---|
36 | print("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
---|
37 | resultMustBe(19);
|
---|
38 |
|
---|
39 | print("ABC");
|
---|
40 | resultMustBe(0);
|
---|
41 |
|
---|
42 | outputMustBe("ABCDEFGHIJKLMNOPQRS");
|
---|
43 | }
|
---|
44 |
|
---|
45 | TEST_F(StringBuilderTests, EmptyString) {
|
---|
46 | print("");
|
---|
47 | resultMustBe(0);
|
---|
48 | outputMustBe("");
|
---|
49 | }
|
---|
50 |
|
---|
51 | TEST_F(StringBuilderTests, OneString) {
|
---|
52 | print("ABCD");
|
---|
53 | resultMustBe(4);
|
---|
54 | outputMustBe("ABCD");
|
---|
55 | }
|
---|
56 |
|
---|
57 | TEST_F(StringBuilderTests, TwoStrings) {
|
---|
58 | print("ABCD");
|
---|
59 | resultMustBe(4);
|
---|
60 |
|
---|
61 | print("EFGH");
|
---|
62 | resultMustBe(4);
|
---|
63 |
|
---|
64 | outputMustBe("ABCDEFGH");
|
---|
65 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.