F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StringTest.hpp
Go to the documentation of this file.
1// ======================================================================
2// \title StringTest.hpp
3// \author T. Chieu
4// \brief hpp file for StringTest class
5//
6// \copyright
7// Copyright (C) 2009-2022 California Institute of Technology.
8// ALL RIGHTS RESERVED. United States Government Sponsorship
9// acknowledged.
10//
11// ======================================================================
12
13#ifndef FPP_TEST_STRING_TEST_HPP
14#define FPP_TEST_STRING_TEST_HPP
15
17
18#include "Fw/Types/String.hpp"
20
21#include "gtest/gtest.h"
22
23namespace FppTest {
24
25 namespace String {
26
27 // Get the size of a string type
28 template <typename StringType>
29 U32 getSize() {
30 return 80;
31 }
32
33 } // namespace String
34
35} // namespace FppTest
36
37// Test a nested string class
38template <class StringType>
39class StringTest : public ::testing::Test {
40protected:
41 void SetUp() override {
42 size = FppTest::String::getSize<StringType>();
43
45
46 char fwStrBuf1[Fw::String::STRING_SIZE];
47 FppTest::Utils::setString(fwStrBuf1, sizeof(fwStrBuf1));
48 fwStr = fwStrBuf1;
49
50 // Truncate fwStr for comparison
51 char fwStrBuf2[size];
53 fwSubstr = fwStrBuf2;
54 }
55
56 U32 size;
57 char src[StringType::SERIALIZED_SIZE];
58
61};
62
64
65// Test string capacity and default constructor
67 TypeParam str;
68
69 // Capacity
70 ASSERT_EQ(str.getCapacity(), this->size);
71
72 // Serialized size
73 ASSERT_EQ(
74 TypeParam::SERIALIZED_SIZE,
75 this->size + sizeof(FwBuffSizeType)
76 );
77
78 // Default constructors
79 ASSERT_STREQ(str.toChar(), "");
80}
81
82// Test string constructors
83TYPED_TEST_P(StringTest, Constructors) {
84 // Char array constructor
85 TypeParam str1(this->src);
86 ASSERT_STREQ(str1.toChar(), this->src);
87
88 // Copy constructor
89 TypeParam str2(str1);
90 ASSERT_STREQ(str2.toChar(), str1.toChar());
91
92 // Fw::StringBase constructor
93 TypeParam str3(this->fwStr);
94 ASSERT_STREQ(str3.toChar(), this->fwSubstr.toChar());
95}
96
97// Test string assignment operator
98TYPED_TEST_P(StringTest, AssignmentOp) {
99 TypeParam str1;
100 TypeParam str2;
101 TypeParam str3;
102
103 // Char array assignment
104 str1 = this->src;
105 ASSERT_STREQ(str1.toChar(), this->src);
106
107 // Copy assignment
108 TypeParam& strRef = str1;
109 str1 = strRef;
110 ASSERT_EQ(&str1, &strRef);
111
112 str2 = str1;
113 ASSERT_STREQ(str1.toChar(), str1.toChar());
114
115 // Fw::StringBase assignment
116 Fw::StringBase& sbRef = str1;
117 str1 = sbRef;
118 ASSERT_EQ(&str1, &sbRef);
119
120 str3 = this->fwStr;
121 ASSERT_STREQ(str3.toChar(), this->fwSubstr.toChar());
122}
123
124// Register all test patterns
126 Default,
127 Constructors,
128 AssignmentOp
129);
130
131#endif
U16 FwBuffSizeType
Definition FpConfig.h:30
TYPED_TEST_P(StringTest, Default)
REGISTER_TYPED_TEST_SUITE_P(StringTest, Default, Constructors, AssignmentOp)
TYPED_TEST_SUITE_P(StringTest)
const char * toChar() const
gets char buffer
Definition String.cpp:48
@ STRING_SIZE
Storage for string.
Definition String.hpp:15
Fw::String fwStr
void SetUp() override
Fw::String fwSubstr
char src[StringType::SERIALIZED_SIZE]
void setString(char *buf, U32 size)
Definition Utils.cpp:41
char * string_copy(char *destination, const char *source, U32 num)
copy string with null-termination guaranteed