blob: 76a2af5445bed732800bde25fb6b12aa8524ae22 [file] [log] [blame]
Jiyong Park22b4ecd2018-07-23 23:34:42 +09001/*
2 * Copyright (C) 2018, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "code_writer.h"
18
19#include <gtest/gtest.h>
20#include <string>
21
22using android::aidl::CodeWriter;
23using std::string;
24using std::unique_ptr;
25
26namespace android {
27namespace aidl {
28
29TEST(CodeWriterTest, AppendOperator) {
30 string str;
31 CodeWriterPtr ptr = CodeWriter::ForString(&str);
32 CodeWriter& writer = *ptr;
33 writer << "Write this";
34 writer.Close();
35 EXPECT_EQ(str, "Write this");
36}
37
38TEST(CodeWriterTest, AppendOperatorCascade) {
39 string str;
40 CodeWriterPtr ptr = CodeWriter::ForString(&str);
41 CodeWriter& writer = *ptr;
42 writer << "Write this " << "and that";
43 writer.Close();
44 EXPECT_EQ(str, "Write this and that");
45}
46
Jooyung Han9969b9d2020-11-28 08:42:37 +090047TEST(CodeWriterTest, WorksWithNonAscii) {
48 // Due to b/174366536(basic_stringbuf implicit-conversion), the following snippet crashes
49 // std::stringstream s;
50 // s << "가";
51 std::string str;
52 CodeWriterPtr ptr = CodeWriter::ForString(&str);
53 CodeWriter& writer = *ptr;
54 writer << "가";
55 writer.Close();
56 EXPECT_EQ(str, "가");
57}
58
Jiyong Park22b4ecd2018-07-23 23:34:42 +090059} // namespace aidl
60} // namespace android