test/src/engine_tests/DeviceModelTests.cc
branchsync_test_refactor
changeset 3320 49df110e65d2
parent 3307 b3d26f9f0225
     1.1 --- a/test/src/engine_tests/DeviceModelTests.cc	Tue Feb 26 06:02:21 2019 +0100
     1.2 +++ b/test/src/engine_tests/DeviceModelTests.cc	Tue Feb 26 08:43:48 2019 +0100
     1.3 @@ -22,6 +22,23 @@
     1.4  
     1.5  using namespace std;
     1.6  
     1.7 +static void remove_sync_mails(vector<message*> &mails) {
     1.8 +    for (vector<message*>::iterator it = mails.begin(); it != mails.end(); ) {
     1.9 +        stringpair_list_t* opt_fields = (*it)->opt_fields;
    1.10 +        bool erased = false;
    1.11 +        while (opt_fields && opt_fields->value && opt_fields->value->key && opt_fields->value->value) {
    1.12 +            if (strcmp(opt_fields->value->key, "pEp-auto-consume") == 0 &&
    1.13 +                strcmp(opt_fields->value->value, "yes") == 0) {
    1.14 +                it = mails.erase(it);
    1.15 +                erased = true;
    1.16 +            }
    1.17 +            opt_fields = opt_fields->next;
    1.18 +        }
    1.19 +        if (!erased)
    1.20 +            it++;
    1.21 +    }
    1.22 +}
    1.23 +
    1.24  DeviceModelTests::DeviceModelTests(string suitename, string test_home_dir) :
    1.25      EngineTestIndividualSuite::EngineTestIndividualSuite(suitename, test_home_dir, false) {
    1.26      add_test_to_suite(std::pair<std::string, void (Test::Suite::*)()>(string("DeviceModelTests::check_device_model"),
    1.27 @@ -333,8 +350,6 @@
    1.28          
    1.29          vector<string> inbox_list;
    1.30          second_device->check_mail(inbox_list);
    1.31 -        TEST_ASSERT_MSG(inbox_list.size() == 1, 
    1.32 -                        (string("Second device received ") + to_string(inbox_list.size()) + " emails, should have received 1.").c_str());
    1.33  
    1.34          vector<message*> inbox_mails;
    1.35          stringlist_t* keylist = NULL;
    1.36 @@ -342,6 +357,7 @@
    1.37          PEP_decrypt_flags_t flags;
    1.38          
    1.39          second_device->read_mail(inbox_list, inbox_mails);
    1.40 +        remove_sync_mails(inbox_mails);
    1.41          TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
    1.42          
    1.43          // Get Alex's key
    1.44 @@ -376,13 +392,14 @@
    1.45          msg = NULL;
    1.46              
    1.47          second_device->check_mail(inbox_list);
    1.48 -        TEST_ASSERT_MSG(inbox_list.size() == 1, 
    1.49 -                        (string("Second device received ") + to_string(inbox_list.size()) + " emails, should have received 1.").c_str());
    1.50 -    
    1.51 +            
    1.52          keylist = NULL;
    1.53          flags = 0;
    1.54          
    1.55          second_device->read_mail(inbox_list, inbox_mails);
    1.56 +        
    1.57 +        remove_sync_mails(inbox_mails);
    1.58 +        
    1.59          TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
    1.60          
    1.61          // Get Charmander's key
    1.62 @@ -421,11 +438,9 @@
    1.63          first_device->grab_context(second_device);
    1.64          enc_msg = NULL;
    1.65  
    1.66 -        first_device->check_mail(inbox_list);
    1.67 -        TEST_ASSERT_MSG(inbox_list.size() == 1, 
    1.68 -                        (string("First device received ") + to_string(inbox_list.size()) + " emails, should have received 1.").c_str());
    1.69 -            
    1.70 +        first_device->check_mail(inbox_list);            
    1.71          first_device->read_mail(inbox_list, inbox_mails);
    1.72 +        remove_sync_mails(inbox_mails);
    1.73          TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
    1.74          
    1.75          status = decrypt_message(first_device->session,
    1.76 @@ -448,10 +463,10 @@
    1.77          third_device->grab_context(first_device);
    1.78  
    1.79          third_device->check_mail(inbox_list);
    1.80 -        TEST_ASSERT_MSG(inbox_list.size() == 1, 
    1.81 -                        (string("Third device received ") + to_string(inbox_list.size()) + " emails, should have received 1.").c_str());
    1.82              
    1.83          third_device->read_mail(inbox_list, inbox_mails);
    1.84 +        remove_sync_mails(inbox_mails);
    1.85 +
    1.86          TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
    1.87          
    1.88          status = decrypt_message(third_device->session,
    1.89 @@ -531,15 +546,14 @@
    1.90          
    1.91          vector<string> inbox_list;
    1.92          pEpTestDevice::active->check_mail(inbox_list);
    1.93 -        TEST_ASSERT_MSG(inbox_list.size() == 1, 
    1.94 -                        (string("Second device received ") + to_string(inbox_list.size()) + " emails, should have received 1.").c_str());
    1.95  
    1.96          vector<message*> inbox_mails;
    1.97          stringlist_t* keylist = NULL;
    1.98          PEP_rating rating;
    1.99          PEP_decrypt_flags_t flags;
   1.100 -        
   1.101          pEpTestDevice::active->read_mail(inbox_list, inbox_mails);
   1.102 +        remove_sync_mails(inbox_mails);
   1.103 +
   1.104          TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
   1.105          
   1.106          // Get Alex's key
   1.107 @@ -574,14 +588,12 @@
   1.108          pEpTestDevice::switch_context(second_device);
   1.109          msg = NULL;
   1.110              
   1.111 -        pEpTestDevice::active->check_mail(inbox_list);
   1.112 -        TEST_ASSERT_MSG(inbox_list.size() == 1, 
   1.113 -                        (string("Second device received ") + to_string(inbox_list.size()) + " emails, should have received 1.").c_str());
   1.114 -    
   1.115 +        pEpTestDevice::active->check_mail(inbox_list);    
   1.116          keylist = NULL;
   1.117          flags = 0;
   1.118 -        
   1.119          pEpTestDevice::active->read_mail(inbox_list, inbox_mails);
   1.120 +        remove_sync_mails(inbox_mails);
   1.121 +
   1.122          TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
   1.123          
   1.124          // Get Charmander's key
   1.125 @@ -623,10 +635,9 @@
   1.126          enc_msg = NULL;
   1.127  
   1.128          pEpTestDevice::active->check_mail(inbox_list);
   1.129 -        TEST_ASSERT_MSG(inbox_list.size() == 1, 
   1.130 -                        (string("First device received ") + to_string(inbox_list.size()) + " emails, should have received 1.").c_str());
   1.131              
   1.132          pEpTestDevice::active->read_mail(inbox_list, inbox_mails);
   1.133 +        remove_sync_mails(inbox_mails);
   1.134          TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
   1.135          
   1.136          status = decrypt_message(pEpTestDevice::active->session,
   1.137 @@ -649,10 +660,8 @@
   1.138          pEpTestDevice::switch_context(third_device);
   1.139  
   1.140          pEpTestDevice::active->check_mail(inbox_list);
   1.141 -        TEST_ASSERT_MSG(inbox_list.size() == 1, 
   1.142 -                        (string("Third device received ") + to_string(inbox_list.size()) + " emails, should have received 1.").c_str());
   1.143 -            
   1.144          pEpTestDevice::active->read_mail(inbox_list, inbox_mails);
   1.145 +        remove_sync_mails(inbox_mails);
   1.146          TEST_ASSERT(inbox_mails.size() == 1 && inbox_mails.at(0));
   1.147          
   1.148          status = decrypt_message(pEpTestDevice::active->session,