henrika | f0dc5c5 | 2020-04-09 18:46:00 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "rtc_base/strings/string_format.h" |
| 12 | |
| 13 | #include "rtc_base/checks.h" |
| 14 | #include "test/gtest.h" |
| 15 | |
| 16 | namespace rtc { |
| 17 | |
| 18 | TEST(StringFormatTest, Empty) { |
| 19 | EXPECT_EQ("", StringFormat("%s", "")); |
| 20 | } |
| 21 | |
| 22 | TEST(StringFormatTest, Misc) { |
| 23 | EXPECT_EQ("123hello w", StringFormat("%3d%2s %1c", 123, "hello", 'w')); |
| 24 | EXPECT_EQ("3 = three", StringFormat("%d = %s", 1 + 2, "three")); |
| 25 | } |
| 26 | |
| 27 | TEST(StringFormatTest, MaxSizeShouldWork) { |
| 28 | const int kSrcLen = 512; |
| 29 | char str[kSrcLen]; |
| 30 | std::fill_n(str, kSrcLen, 'A'); |
| 31 | str[kSrcLen - 1] = 0; |
| 32 | EXPECT_EQ(str, StringFormat("%s", str)); |
| 33 | } |
| 34 | |
| 35 | } // namespace rtc |