blob: 0403ab85296c4246313f0d776b237a2497cb8c7a [file] [log] [blame]
Tommifef05002018-02-27 13:51:08 +01001/*
2 * Copyright 2018 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_builder.h"
12
13#include "rtc_base/checks.h"
14#include "rtc_base/gunit.h"
15#include "rtc_base/stringutils.h"
16
17namespace rtc {
18
19TEST(SimpleStringBuilder, Limit) {
20 SimpleStringBuilder<10> sb;
21 EXPECT_EQ(0u, strlen(sb.str()));
22
23 // Test that for a SSB with a buffer size of 10, that we can write 9 chars
24 // into it.
25 sb << "012345678"; // 9 characters + '\0'.
26 EXPECT_EQ(0, strcmp(sb.str(), "012345678"));
27}
28
29TEST(SimpleStringBuilder, NumbersAndChars) {
30 SimpleStringBuilder<100> sb;
31 sb << 1 << ':' << 2.1 << ":" << 2.2f << ':' << 78187493520ll << ':'
32 << 78187493520ul;
33 EXPECT_EQ(0, strcmp(sb.str(), "1:2.100000:2.200000:78187493520:78187493520"));
34}
35
36TEST(SimpleStringBuilder, Format) {
37 SimpleStringBuilder<100> sb;
38 sb << "Here we go - ";
39 sb.AppendFormat("This is a hex formatted value: 0x%08x", 3735928559);
40 EXPECT_EQ(0,
41 strcmp(sb.str(),
42 "Here we go - This is a hex formatted value: 0xdeadbeef"));
43}
44
45TEST(SimpleStringBuilder, StdString) {
46 SimpleStringBuilder<100> sb;
47 std::string str = "does this work?";
48 sb << str;
49 EXPECT_EQ(str, sb.str());
50}
51
52} // namespace rtc