@@ -129,7 +129,7 @@ TEST(RESTapiTest, example) {
129129 {addLink: {src: "sp.bottomUpOut", dest: "tm.bottomUpIn"}}
130130 ]})" ;
131131
132-
132+ // create the network object
133133 res = client.Post (" /network" , config, " application/json" );
134134 ASSERT_TRUE (res && res->status /100 == 2 && res->body .size () == 5 ) << " Failed Response to POST /network request." ;
135135 std::string id = res->body .substr (0 ,4 );
@@ -170,4 +170,59 @@ TEST(RESTapiTest, example) {
170170
171171 threadObj.join (); // wait until server thread has stopped.
172172}
173+
174+ TEST (RESTapiTest, test_delete) {
175+ std::thread threadObj (serverThread); // start REST server
176+ std::this_thread::sleep_for (std::chrono::seconds (1 )); // give server time to start
177+
178+ // Client thread.
179+ const httplib::Params noParams;
180+ char message[1000 ];
181+
182+ httplib::Client client (" 127.0.0.1" , port);
183+ client.set_timeout_sec (30 );
184+
185+ // Configure a NetworkAPI example
186+ // See Network.configure() for syntax.
187+ // Simple situation Encoder ==> SP ==> TM
188+ // Compare this to the napi_sine example.
189+ std::string config = R"(
190+ {network: [
191+ {addRegion: {name: "encoder", type: "RDSEEncoderRegion", params: {size: 1000, sparsity: 0.2, radius: 0.03, seed: 2019, noise: 0.01}}},
192+ {addRegion: {name: "sp", type: "SPRegion", params: {columnCount: 2048, globalInhibition: true}}},
193+ {addRegion: {name: "tm", type: "TMRegion", params: {cellsPerColumn: 8, orColumnOutputs: true}}},
194+ {addLink: {src: "encoder.encoded", dest: "sp.bottomUpIn"}},
195+ {addLink: {src: "sp.bottomUpOut", dest: "tm.bottomUpIn"}}
196+ ]})" ;
197+
198+ // create the network object
199+ auto res = client.Post (" /network" , config, " application/json" );
200+ ASSERT_TRUE (res && res->status / 100 == 2 && res->body .size () == 5 ) << " Failed Response to POST /network request." ;
201+ std::string id = res->body .substr (0 , 4 );
202+
203+ // Now delete the second link.
204+ snprintf (message, sizeof (message), " /network/%s/link/sp.bottomUpOut/tm.bottomUpIn" , id.c_str ());
205+ res = client.Delete (message);
206+ ASSERT_TRUE (res && res->status / 100 == 2 ) << " DELETE link message failed." ;
207+ EXPECT_STREQ (trim (res->body ).c_str (), " OK" ) << " Response to DELETE Link request" ;
208+
209+ // Delete a region
210+ snprintf (message, sizeof (message), " /network/%s/region/tm" , id.c_str ());
211+ res = client.Delete (message);
212+ ASSERT_TRUE (res && res->status / 100 == 2 ) << " DELETE region message failed." ;
213+ EXPECT_STREQ (trim (res->body ).c_str (), " OK" ) << " Response to DELETE Link request" ;
214+
215+ // Delete a Network
216+ snprintf (message, sizeof (message), " /network/%s/ALL" , id.c_str ());
217+ res = client.Delete (message);
218+ ASSERT_TRUE (res && res->status / 100 == 2 ) << " DELETE region message failed." ;
219+ EXPECT_STREQ (trim (res->body ).c_str (), " OK" ) << " Response to DELETE Link request" ;
220+
221+
222+
223+ // wrap up
224+ res = client.Get (" /stop" ); // stop the server.
225+ threadObj.join (); // wait until server thread has stopped.
226+ }
227+
173228} // namespace testing
0 commit comments