Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfb31f8e

Browse files
kptdobesamtstern
authored andcommitted
[FirebaseObject] Error message is never resetFirebaseExtended#390 (FirebaseExtended#391)
1 parent33363f7 commitfb31f8e

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

‎contrib/test/FirebaseArduino_test.cpp

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ TEST(FirebaseObjectTest, GetInt) {
4545

4646
TEST(FirebaseObjectTest, GetFloat) {
4747
{
48-
FirebaseObjectobj("43.0");
49-
EXPECT_EQ(43, obj.getFloat());
48+
FirebaseObjectobj("43.1");
49+
EXPECT_FLOAT_EQ(43.1, obj.getFloat());
5050
EXPECT_TRUE(obj.success());
5151
EXPECT_FALSE(obj.failed());
5252
EXPECT_EQ(obj.error(),"");
5353
}
5454
{
5555
FirebaseObjectobj("43");
56-
EXPECT_EQ(43, obj.getFloat());
56+
EXPECT_FLOAT_EQ(43, obj.getFloat());
5757
EXPECT_TRUE(obj.success());
5858
EXPECT_FALSE(obj.failed());
5959
EXPECT_EQ(obj.error(),"");
@@ -112,6 +112,59 @@ TEST(FirebaseObjectTest, GetStringFailure) {
112112
EXPECT_EQ(obj.error(),"failed to convert to string");
113113
}
114114

115+
TEST(FirebaseObjectTest, GetTwice) {
116+
{
117+
FirebaseObjectobj("{\"foo\":\"bar\"}");
118+
EXPECT_EQ(obj.getString("hop"),"");
119+
EXPECT_FALSE(obj.success());
120+
EXPECT_TRUE(obj.failed());
121+
EXPECT_EQ(obj.error(),"failed to convert to string");
122+
123+
EXPECT_EQ(obj.getString("foo"),"bar");
124+
EXPECT_TRUE(obj.success());
125+
EXPECT_FALSE(obj.failed());
126+
EXPECT_EQ(obj.error(),"");
127+
}
128+
{
129+
FirebaseObjectobj("{\"foo\": 42}");
130+
EXPECT_EQ(obj.getInt("hop"),0);
131+
EXPECT_FALSE(obj.success());
132+
EXPECT_TRUE(obj.failed());
133+
EXPECT_EQ(obj.error(),"failed to convert to number");
134+
135+
EXPECT_EQ(obj.getInt("foo"),42);
136+
EXPECT_TRUE(obj.success());
137+
EXPECT_FALSE(obj.failed());
138+
EXPECT_EQ(obj.error(),"");
139+
}
140+
{
141+
FirebaseObjectobj("{\"foo\": true}");
142+
EXPECT_EQ(obj.getBool("hop"),0);
143+
EXPECT_FALSE(obj.success());
144+
EXPECT_TRUE(obj.failed());
145+
EXPECT_EQ(obj.error(),"failed to convert to bool");
146+
147+
EXPECT_EQ(obj.getBool("foo"),true);
148+
EXPECT_TRUE(obj.success());
149+
EXPECT_FALSE(obj.failed());
150+
EXPECT_EQ(obj.error(),"");
151+
}
152+
{
153+
FirebaseObjectobj("{\"foo\": 43.1}");
154+
EXPECT_FLOAT_EQ(obj.getFloat("hop"),0);
155+
EXPECT_FALSE(obj.success());
156+
EXPECT_TRUE(obj.failed());
157+
EXPECT_EQ(obj.error(),"failed to convert to number");
158+
159+
EXPECT_FLOAT_EQ(obj.getFloat("foo"),43.1);
160+
EXPECT_TRUE(obj.success());
161+
EXPECT_FALSE(obj.failed());
162+
EXPECT_EQ(obj.error(),"");
163+
}
164+
}
165+
166+
167+
115168
intmain(int argc,char **argv) {
116169
::testing::InitGoogleTest(&argc, argv);
117170
returnRUN_ALL_TESTS();

‎src/FirebaseObject.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ bool FirebaseObject::getBool(const String& path) const {
3232
error_ ="failed to convert to bool";
3333
return0;
3434
}
35+
error_ ="";
3536
returnstatic_cast<bool>(variant);
3637
}
3738

@@ -41,6 +42,7 @@ int FirebaseObject::getInt(const String& path) const {
4142
error_ ="failed to convert to number";
4243
return0;
4344
}
45+
error_ ="";
4446
returnstatic_cast<int>(variant);
4547
}
4648

@@ -50,6 +52,7 @@ float FirebaseObject::getFloat(const String& path) const {
5052
error_ ="failed to convert to number";
5153
return0;
5254
}
55+
error_ ="";
5356
returnstatic_cast<float>(variant);
5457
}
5558

@@ -59,6 +62,7 @@ String FirebaseObject::getString(const String& path) const {
5962
error_ ="failed to convert to string";
6063
return"";
6164
}
65+
error_ ="";
6266
returnstatic_cast<constchar*>(variant);
6367
}
6468

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp