@@ -20,13 +20,26 @@ unittest(Client) {
2020}
2121
2222unittest (Client_copy_constructor) {
23- { // Client object contains a reference to a String object
24- Client c1; // Constructor instantiates a String (s1)
25- Client c2; // Constructor instantiates a String (s2)
26- c2 = c1; // Does c2 get a reference to s1 or a copy of it?
27- } // End of scope calls destructor on c1 and c2
28- assertTrue (true ); // Was s1 deleted once (with c1) or twice (also with c2)?
29- // Was s2 deleted at all (should be during assignment)?
23+ { // Client object contains a reference to a String object
24+ Client c1; // Constructor instantiates a String (string1)
25+ Client c2; // Constructor instantiates a String (string2)
26+ c1.write (' 1' );
27+ c2.write (' 2' );
28+ assertEqual (" 1" , *(c1.mGodmodeDataIn ));
29+ assertEqual (" 2" , *(c2.mGodmodeDataIn ));
30+ c2 = c1; // c2 should get a copy of s1, not a reference to it
31+ // and string2 should have been deleted during the assignment
32+ assertNotEqual (c1.mGodmodeDataIn , c2.mGodmodeDataIn );
33+ assertEqual (" 1" , *(c1.mGodmodeDataIn ));
34+ assertEqual (" 1" , *(c2.mGodmodeDataIn ));
35+ c1.write (' 1' );
36+ c2.write (' 2' );
37+ assertEqual (" 11" , *(c1.mGodmodeDataIn ));
38+ assertEqual (" 12" , *(c2.mGodmodeDataIn ));
39+ } // End of scope calls destructor on c1 and c2
40+ // Memory monitoring will give an error if delete is called twice on string1
41+ // The following assertion is just to confirm that we got through the above
42+ assertTrue (true );
3043}
3144
3245unittest (IPAddress) {
0 commit comments