xref: /aosp_15_r20/external/openscreen/util/stringprintf_unittest.cc (revision 3f982cf4871df8771c9d4abe6e9a6f8d829b2736)
1 // Copyright 2019 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "util/stringprintf.h"
6 
7 #include "gtest/gtest.h"
8 
9 namespace openscreen {
10 namespace {
11 
TEST(StringPrintf,ProducesFormattedStrings)12 TEST(StringPrintf, ProducesFormattedStrings) {
13   EXPECT_EQ("no args", StringPrintf("no args"));
14   EXPECT_EQ("", StringPrintf("%s", ""));
15   EXPECT_EQ("42", StringPrintf("%d", 42));
16   EXPECT_EQ(
17       "The result of foo(1, 2) looks good!",
18       StringPrintf("The result of foo(%d, %d) looks %s%c", 1, 2, "good", '!'));
19 }
20 
TEST(HexEncode,ProducesEmptyStringFromEmptyByteArray)21 TEST(HexEncode, ProducesEmptyStringFromEmptyByteArray) {
22   const uint8_t kSomeMemoryLocation = 0;
23   EXPECT_EQ("", HexEncode(&kSomeMemoryLocation, 0));
24 }
25 
TEST(HexEncode,ProducesHexStringsFromBytes)26 TEST(HexEncode, ProducesHexStringsFromBytes) {
27   const uint8_t kMessage[] = "Hello world!";
28   const char kMessageInHex[] = "48656c6c6f20776f726c642100";
29   EXPECT_EQ(kMessageInHex, HexEncode(kMessage, sizeof(kMessage)));
30 }
31 
32 }  // namespace
33 }  // namespace openscreen
34