1// Copyright 2008 Google Inc.
2// Author: Lincoln Smith
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#include <config.h>
17#include <string>
18#include "google/output_string.h"
19#include "testing.h"
20
21#ifdef HAVE_EXT_ROPE
22#include <ext/rope>
23#include "output_string_crope.h"
24#endif  // HAVE_EXT_ROPE
25
26namespace open_vcdiff {
27namespace {
28
29class OutputStringTest : public testing::Test {
30 public:
31  typedef std::string string;
32
33  OutputStringTest() : string_("ab"), output_string_(&string_) { }
34
35  virtual ~OutputStringTest() { }
36
37 protected:
38  string string_;
39  OutputString<string> output_string_;
40};
41
42TEST_F(OutputStringTest, Append) {
43  output_string_.append("cdef", 2);
44  EXPECT_EQ("abcd", string_);
45}
46
47TEST_F(OutputStringTest, Clear) {
48  output_string_.clear();
49  EXPECT_EQ("", string_);
50}
51
52TEST_F(OutputStringTest, PushBack) {
53  output_string_.push_back('c');
54  EXPECT_EQ("abc", string_);
55}
56
57TEST_F(OutputStringTest, Reserve) {
58  const size_t initial_capacity = string_.capacity();
59  string_.resize(string_.capacity());
60  EXPECT_EQ(initial_capacity, string_.capacity());
61  output_string_.ReserveAdditionalBytes(1);
62  EXPECT_LE(initial_capacity + 1, string_.capacity());
63}
64
65TEST_F(OutputStringTest, Size) {
66  EXPECT_EQ(string_.size(), output_string_.size());
67  string_.push_back('c');
68  EXPECT_EQ(string_.size(), output_string_.size());
69  string_.clear();
70  EXPECT_EQ(string_.size(), output_string_.size());
71}
72
73#ifdef HAVE_EXT_ROPE
74class OutputCRopeTest : public testing::Test {
75 public:
76  typedef __gnu_cxx::crope crope;
77
78  OutputCRopeTest() : crope_("ab"), output_crope_(&crope_) { }
79
80  virtual ~OutputCRopeTest() { }
81
82 protected:
83  crope crope_;
84  OutputCrope output_crope_;
85};
86
87TEST_F(OutputCRopeTest, Append) {
88  output_crope_.append("cdef", 2);
89  crope expected_abcd("abcd");
90  EXPECT_EQ(expected_abcd, crope_);
91}
92
93TEST_F(OutputCRopeTest, Clear) {
94  output_crope_.clear();
95  crope expected_empty;
96  EXPECT_EQ(expected_empty, crope_);
97}
98
99TEST_F(OutputCRopeTest, PushBack) {
100  output_crope_.push_back('c');
101  crope expected_abc("abc");
102  EXPECT_EQ(expected_abc, crope_);
103}
104
105TEST_F(OutputCRopeTest, Size) {
106  EXPECT_EQ(crope_.size(), output_crope_.size());
107  crope_.push_back('c');
108  EXPECT_EQ(crope_.size(), output_crope_.size());
109  crope_.clear();
110  EXPECT_EQ(crope_.size(), output_crope_.size());
111}
112#endif  // HAVE_EXT_ROPE
113
114}  // anonymous namespace
115}  // namespace open_vcdiff
116