Skip to content

Commit 6182206

Browse files
committed
Fixing memory leaks in unit tests
1 parent 11a8f57 commit 6182206

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

Diff for: extras/test/src/test_callback.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ SCENARIO("After a connection/reconnection an incoming cbor payload is processed
162162
SCENARIO("Primitive property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback applies the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the cloud one.") {
163163
GIVEN("CloudProtocol::V2") {
164164
bool test = true;
165-
ArduinoCloudProperty *p = new CloudWrapperBool(test);
165+
std::unique_ptr<ArduinoCloudProperty> p(new CloudWrapperBool(test));
166166
sync_callback_called = false;
167167
change_callback_called = false;
168168

@@ -192,7 +192,7 @@ SCENARIO("Primitive property: After a connection/reconnection an incoming cbor p
192192
SCENARIO("Primitive property: After a connection/reconnection an incoming cbor payload is processed and the synchronization callback is executed. The sync callback apply the AUTO_SYNC policy (the most recent value between the local one and the cloud one is finally assigned to the property). The onUpdate function is called if the cloud value is the most recent one. In this scenario the most updated value is the local one.") {
193193
GIVEN("CloudProtocol::V2") {
194194
bool test = true;
195-
ArduinoCloudProperty *p = new CloudWrapperBool(test);
195+
std::unique_ptr<ArduinoCloudProperty> p(new CloudWrapperBool(test));
196196
sync_callback_called = false;
197197
change_callback_called = false;
198198

Diff for: extras/test/src/test_decode.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <catch.hpp>
1010

11+
#include <memory>
12+
1113
#include <util/CBORTestUtil.h>
1214
#include <ArduinoCloudThing.h>
1315
#include "types/CloudWrapperBool.h"
@@ -483,15 +485,15 @@ SCENARIO("Arduino Cloud Properties are decoded", "[ArduinoCloudThing::decode]")
483485
String str_test;
484486
str_test = "str_test";
485487

486-
ArduinoCloudProperty *i = new CloudWrapperInt(int_test);
487-
ArduinoCloudProperty *b = new CloudWrapperBool(bool_test);
488-
ArduinoCloudProperty *f = new CloudWrapperFloat(float_test);
489-
ArduinoCloudProperty *s = new CloudWrapperString(str_test);
488+
std::unique_ptr<ArduinoCloudProperty> i(new CloudWrapperInt(int_test));
489+
std::unique_ptr<ArduinoCloudProperty> b(new CloudWrapperBool(bool_test));
490+
std::unique_ptr<ArduinoCloudProperty> f(new CloudWrapperFloat(float_test));
491+
std::unique_ptr<ArduinoCloudProperty> s(new CloudWrapperString(str_test));
490492

491-
thing.addPropertyReal(*b, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS);
492-
thing.addPropertyReal(*i, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS);
493+
thing.addPropertyReal(*b, "bool_test", Permission::ReadWrite).onSync(CLOUD_WINS);
494+
thing.addPropertyReal(*i, "int_test", Permission::ReadWrite).onSync(CLOUD_WINS);
493495
thing.addPropertyReal(*f, "float_test", Permission::ReadWrite).onSync(CLOUD_WINS);
494-
thing.addPropertyReal(*s, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS);
496+
thing.addPropertyReal(*s, "str_test", Permission::ReadWrite).onSync(CLOUD_WINS);
495497

496498
thing.updateTimestampOnLocallyChangedProperties();
497499

Diff for: extras/test/src/test_encode.cpp

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <catch.hpp>
1010

11+
#include <memory>
12+
1113
#include <util/CBORTestUtil.h>
1214
#include <ArduinoCloudThing.h>
1315
#include "types/CloudWrapperBool.h"
@@ -377,15 +379,15 @@ SCENARIO("Arduino Cloud Properties are encoded", "[ArduinoCloudThing::encode]")
377379
String str_test;
378380
str_test = "str_test";
379381

380-
ArduinoCloudProperty *i = new CloudWrapperInt(int_test);
381-
ArduinoCloudProperty *b = new CloudWrapperBool(bool_test);
382-
ArduinoCloudProperty *f = new CloudWrapperFloat(float_test);
383-
ArduinoCloudProperty *s = new CloudWrapperString(str_test);
382+
std::unique_ptr<ArduinoCloudProperty> i(new CloudWrapperInt(int_test));
383+
std::unique_ptr<ArduinoCloudProperty> b(new CloudWrapperBool(bool_test));
384+
std::unique_ptr<ArduinoCloudProperty> f(new CloudWrapperFloat(float_test));
385+
std::unique_ptr<ArduinoCloudProperty> s(new CloudWrapperString(str_test));
384386

385-
thing.addPropertyReal(*i, "int_test", Permission::ReadWrite);
386-
thing.addPropertyReal(*b, "bool_test", Permission::ReadWrite);
387+
thing.addPropertyReal(*i, "int_test", Permission::ReadWrite);
388+
thing.addPropertyReal(*b, "bool_test", Permission::ReadWrite);
387389
thing.addPropertyReal(*f, "float_test", Permission::ReadWrite);
388-
thing.addPropertyReal(*s, "str_test", Permission::ReadWrite);
390+
thing.addPropertyReal(*s, "str_test", Permission::ReadWrite);
389391

390392
thing.updateTimestampOnLocallyChangedProperties();
391393

0 commit comments

Comments
 (0)