gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ostream_helpers.test.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 Arteris, Inc. and its applicable licensors and
3  * affiliates. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer; redistributions in binary
9  * form must reproduce the above copyright notice, this list of conditions and
10  * the following disclaimer in the documentation and/or other materials
11  * provided with the distribution; neither the name of the copyright holders
12  * nor the names of its contributors may be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <gtest/gtest.h>
29 
30 #include <map>
31 #include <sstream>
32 #include <string_view>
33 #include <vector>
34 
36 
37 using gem5::stl_helpers::operator<<;
38 
39 TEST(OstreamHelpers, pair) {
40  auto p = std::make_pair(1, 2);
41  std::ostringstream os;
42  os << p;
43  EXPECT_EQ(os.str(), "(1, 2)");
44 }
45 
46 TEST(OstreamHelpers, tuple) {
47  auto t = std::make_tuple(true,
48  std::make_pair("Hello", std::string_view("World")), '!');
49  std::ostringstream os;
50  os << t;
51  EXPECT_EQ(os.str(), "(1, (Hello, World), !)");
52 }
53 
54 TEST(OstreamHelpers, vector) {
55  auto v = std::vector<const char*>{"abc", "defg", "hijklm", "\n"};
56  std::ostringstream os;
57  os << v;
58  EXPECT_EQ(os.str(), "[ abc, defg, hijklm, \n, ]");
59 }
60 
61 TEST(OstreamHelpers, map) {
62  auto m = std::map<char, int>{{'a', 0}, {'b', 1}, {'c', 2}, {'d', 3}};
63  std::ostringstream os;
64  os << m;
65  EXPECT_EQ(os.str(), "[ (a, 0), (b, 1), (c, 2), (d, 3), ]");
66 }
gem5::VegaISA::m
m
Definition: pagetable.hh:52
gem5::X86ISA::vector
Bitfield< 15, 8 > vector
Definition: intmessage.hh:48
std::vector< const char * >
ostream_helpers.hh
gem5::VegaISA::t
Bitfield< 51 > t
Definition: pagetable.hh:56
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
TEST
TEST(OstreamHelpers, pair)
Definition: ostream_helpers.test.cc:39
gem5::VegaISA::v
Bitfield< 0 > v
Definition: pagetable.hh:65
gem5::X86ISA::os
Bitfield< 17 > os
Definition: misc.hh:810

Generated on Sun Jul 30 2023 01:56:51 for gem5 by doxygen 1.8.17