// Copyright 2022 Google LLC. All Rights Reserved. This file and proprietary // source code may only be used and distributed under the Widevine License // Agreement. #include "string_format.h" #include #include #include namespace wvutil { TEST(StringFormatTest, SignedInteger) { constexpr char kFormat[] = "Version %d"; constexpr char kResult[] = "Version -123"; std::string result; EXPECT_TRUE(FormatString(&result, kFormat, -123)); EXPECT_EQ(result, kResult); } TEST(StringFormatTest, UnsignedInteger) { constexpr char kFormat[] = "Version %u"; constexpr char kResult[] = "Version 27"; std::string result; EXPECT_TRUE(FormatString(&result, kFormat, 27)); EXPECT_EQ(result, kResult); } TEST(StringFormatTest, HexInteger) { constexpr char kFormat[] = "Version %X"; constexpr char kResult[] = "Version FF"; std::string result; EXPECT_TRUE(FormatString(&result, kFormat, 0xFF)); EXPECT_EQ(result, kResult); } TEST(StringFormatTest, Strings) { constexpr char kFormat[] = "Hello, %s."; constexpr char kResult[] = "Hello, DRM."; std::string result; EXPECT_TRUE(FormatString(&result, kFormat, "DRM")); EXPECT_EQ(result, kResult); } TEST(StringFormatTest, Nothing) { constexpr char kString[] = "No format fields."; std::string result; EXPECT_TRUE(FormatString(&result, kString)); EXPECT_EQ(result, kString); } TEST(StringFormatTest, NullOutput) { constexpr char kString[] = "This will never be referenced."; EXPECT_FALSE(FormatString(nullptr, kString)); } TEST(StringFormatTest, NullFormat) { std::string result; EXPECT_FALSE(FormatString(&result, nullptr)); EXPECT_TRUE(result.empty()); } } // namespace wvutil