diff options
Diffstat (limited to 'osp_base/json/json_writer_unittest.cc')
-rw-r--r-- | osp_base/json/json_writer_unittest.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/osp_base/json/json_writer_unittest.cc b/osp_base/json/json_writer_unittest.cc new file mode 100644 index 00000000..6a4c00e1 --- /dev/null +++ b/osp_base/json/json_writer_unittest.cc @@ -0,0 +1,32 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "osp_base/json/json_writer.h" + +#include "osp_base/error.h" +#include "third_party/googletest/src/googlemock/include/gmock/gmock.h" +#include "third_party/googletest/src/googletest/include/gtest/gtest.h" + +namespace openscreen { + +TEST(JsonWriterTest, NullValueReturnsError) { + JsonWriter writer; + + const auto null_value = Json::Value(); + const auto actual = writer.Write(null_value); + + EXPECT_TRUE(actual.is_error()); + EXPECT_EQ(actual.error().code(), Error::Code::kJsonWriteError); +} + +TEST(JsonWriterTest, ValidValueReturnsString) { + JsonWriter writer; + + const Json::Int64 value = 31337; + const auto actual = writer.Write(value); + + EXPECT_TRUE(actual.is_value()); + EXPECT_EQ(actual.value(), "31337\n"); +} +} // namespace openscreen |