| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- //
- // serial_test.cxx
- // engine-test
- //
- // Created by Sam Jaffe on 6/2/19.
- // Copyright © 2019 Sam Jaffe. All rights reserved.
- //
- #include <sstream>
- #include "mock_renderer.h"
- #include <gmock/gmock.h>
- #include <json/json.h>
- #include <json/reader.h>
- #include "game/engine/serial.hpp"
- Json::Value to_json(std::string const & str) {
- Json::Value json;
- std::stringstream(str) >> json;
- return json;
- }
- struct SerialTest : testing::Test {};
- using testing::Eq;
- TEST_F(SerialTest, ReadsIntegerVector) {
- math::vec2i const expected{{1, 5}};
- std::string const data = "[1,5]";
- EXPECT_THAT(engine::to_vec2i(to_json(data)), Eq(expected));
- }
- TEST_F(SerialTest, ReadsIntegerVectorFromFloats) {
- math::vec2i const expected{{1, 5}};
- std::string const data = "[1.5,5.01]";
- EXPECT_THAT(engine::to_vec2i(to_json(data)), Eq(expected));
- }
- TEST_F(SerialTest, ReadsFloatVector) {
- math::vec2 const expected{{1.5, 5.01}};
- std::string const data = "[1.5,5.01]";
- EXPECT_THAT(engine::to_vec2(to_json(data)), Eq(expected));
- }
- TEST_F(SerialTest, ReadsFloatVectorFromInts) {
- math::vec2 const expected{{1, 5}};
- std::string const data = "[1,5]";
- EXPECT_THAT(engine::to_vec2(to_json(data)), Eq(expected));
- }
- TEST_F(SerialTest, MissingFloatDataIsZero) {
- math::vec2 const expected{{1, 0}};
- std::string const data = "[1]";
- EXPECT_THAT(engine::to_vec2(to_json(data)), Eq(expected));
- }
- TEST_F(SerialTest, FallbackReaderDoesntInvokeIfArray) {
- math::vec2 const expected{{0, 0}};
- std::string const data = "[]";
- EXPECT_THAT(engine::to_vec2(to_json(data), {{1, 5}}), Eq(expected));
- }
- TEST_F(SerialTest, FallbackReaderActivatesOnNull) {
- math::vec2 const expected{{1, 5}};
- std::string const data = "null";
- EXPECT_THAT(engine::to_vec2(to_json(data), {{1, 5}}), Eq(expected));
- }
|