Add simple request cancellation tests 52/29352/15
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Fri, 24 Oct 2014 16:08:42 +0000 (18:08 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Sat, 6 Dec 2014 01:03:24 +0000 (02:03 +0100)
tca05_request_and_cancel* - check cancellation of sent requests
tca06_cancel_fail - checks cancellation of not existing request

Change-Id: I495846f8494dc4ef6e329774039869e10b1b9731

tests/cynara-tests/test_cases_async.cpp

index 8b2a17d..f3f4265 100644 (file)
@@ -84,9 +84,96 @@ void tca04_request_and_process_func()
     client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
 }
 
+void tca05_request_and_cancel1_func()
+{
+    std::string testNo("05");
+    int subtest = 1;
+    cynara_check_id id;
+    RequestEntity callbackData = {RequestFunction(),
+                                  CYNARA_API_ACCESS_DENIED,
+                                  CYNARA_CALL_CAUSE_CANCEL};
+
+    Client client;
+
+    client.createRequest({testNo, subtest}, id, callbackData);
+    client.assertStatus(READWRITE);
+
+    client.cancel(id);
+    client.assertStatus(READWRITE);
+
+    //send request and cancel
+    client.process();
+    client.assertStatus(READ);
+
+    //get answer
+    client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
+}
+
+void tca05_request_and_cancel2_func()
+{
+    std::string testNo("05");
+    int subtest = 2;
+    cynara_check_id id1, id2;
+    Client client;
+
+    RequestEntity callbackData1 = {[&]()->void {client.cancel(id2);},
+                                   CYNARA_API_ACCESS_DENIED,
+                                   CYNARA_CALL_CAUSE_ANSWER};
+    RequestEntity callbackData2 = {RequestFunction(),
+                                   CYNARA_API_ACCESS_DENIED,
+                                   CYNARA_CALL_CAUSE_CANCEL};
+
+    client.createRequest({testNo, subtest}, id1, callbackData1);
+    client.createRequest({testNo, subtest}, id2, callbackData2);
+    client.assertStatus(READWRITE);
+
+    //send requests
+    client.process();
+    client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
+    client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
+}
+
+void tca05_request_and_cancel3_func()
+{
+    std::string testNo("05");
+    int subtest = 3;
+    cynara_check_id id;
+    RequestEntity callbackData = {RequestFunction(),
+                                  CYNARA_API_ACCESS_DENIED,
+                                  CYNARA_CALL_CAUSE_ANSWER};
+
+    Client client;
+
+    client.createRequest({testNo, subtest}, id, callbackData);
+    client.assertStatus(READWRITE);
+
+    //send request
+    client.process();
+    client.assertStatus(READ);
+
+    //get answer
+    client.process(CYNARA_API_SUCCESS, Client::IGNORE_TIMEOUT);
+    client.assertStatus(READ);
+
+    client.cancel(id, CYNARA_API_INVALID_PARAM);
+}
+
+void tca06_cancel_fail_func()
+{
+    cynara_check_id id = 0xDEAD;
+
+    Client client;
+
+    client.cancel(id, CYNARA_API_INVALID_PARAM);
+}
+
 RUNNER_TEST_GROUP_INIT(cynara_async_tests)
 
 RUN_CYNARA_TEST(tca01_initialize)
 RUN_CYNARA_TEST(tca02_empty_cache_miss)
 RUN_CYNARA_TEST(tca03_create_max_requests)
 RUN_CYNARA_TEST(tca04_request_and_process)
+RUN_CYNARA_TEST(tca05_request_and_cancel1)
+RUN_CYNARA_TEST(tca05_request_and_cancel2)
+RUN_CYNARA_TEST(tca05_request_and_cancel3)
+RUN_CYNARA_TEST(tca06_cancel_fail)