Files
oemcrypto/util/test/string_format_unittest.cpp
Fred Gylys-Colwell 562f64f292 Version 18.1
Updates to OEMCrypto API, OPK, ODK, and unit tests.

See the file CHANGELOG.md for details.
2023-03-09 18:06:07 -08:00

65 lines
1.7 KiB
C++

// 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 <gmock/gmock.h>
#include <gtest/gtest.h>
#include <string>
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