add KeyResetMessageTest.codec_test sync
authorVolker Birk <vb@pep-project.org>
Fri, 13 Dec 2019 21:13:32 +0100
branchsync
changeset 427404ad08686053
parent 4273 b18b0e1d9976
child 4275 8e1a09dbad16
add KeyResetMessageTest.codec_test
test/src/KeyResetMessageTest.cc
     1.1 --- a/test/src/KeyResetMessageTest.cc	Thu Dec 12 15:11:14 2019 +0100
     1.2 +++ b/test/src/KeyResetMessageTest.cc	Fri Dec 13 21:13:32 2019 +0100
     1.3 @@ -1437,3 +1437,100 @@
     1.4          ASSERT_EQ(status, PEP_STATUS_OK);
     1.5      }
     1.6  }
     1.7 +
     1.8 +TEST_F(KeyResetMessageTest, codec_test) {
     1.9 +    // create input values
    1.10 +
    1.11 +    pEp_identity *ident1 = new_identity("alice@pep-project.org", "23", "42", "Alice Miller");
    1.12 +    ASSERT_NE(ident1, nullptr);
    1.13 +    const char *key1 = "0123456789abcdef";
    1.14 +    keyreset_command *cmd1 = new_keyreset_command(ident1, key1);
    1.15 +    ASSERT_NE(cmd1, nullptr);
    1.16 +
    1.17 +    keyreset_command_list *il = new_keyreset_command_list(cmd1);
    1.18 +    ASSERT_NE(il, nullptr);
    1.19 +
    1.20 +    pEp_identity *ident2 = new_identity("alice@peptest.ch", "423", "42", "Alice Miller");
    1.21 +    ASSERT_NE(ident2, nullptr);
    1.22 +    const char *key2 = "fedcba9876543210";
    1.23 +    keyreset_command *cmd2 = new_keyreset_command(ident2, key2);
    1.24 +    ASSERT_NE(cmd2, nullptr);
    1.25 +
    1.26 +    keyreset_command_list *_il = keyreset_command_list_add(il, cmd2);
    1.27 +    ASSERT_NE(_il, nullptr);
    1.28 +
    1.29 +    // check created struct
    1.30 +
    1.31 +    ASSERT_NE(il->command, nullptr);
    1.32 +    ASSERT_NE(il->command->ident, nullptr);
    1.33 +    ASSERT_NE(il->command->new_key, nullptr);
    1.34 +
    1.35 +    ASSERT_STREQ(il->command->ident->address, ident1->address);
    1.36 +    ASSERT_STRCASEEQ(il->command->ident->fpr, ident1->fpr);
    1.37 +    ASSERT_STREQ(il->command->ident->user_id, ident1->user_id);
    1.38 +    ASSERT_STREQ(il->command->ident->username, ident1->username);
    1.39 +    ASSERT_STREQ(il->command->new_key, key1);
    1.40 +
    1.41 +    ASSERT_NE(il->next, nullptr);
    1.42 +    ASSERT_NE(il->next->command, nullptr);
    1.43 +    ASSERT_NE(il->next->command->ident, nullptr);
    1.44 +    ASSERT_NE(il->next->command->new_key, nullptr);
    1.45 +
    1.46 +    ASSERT_STREQ(il->next->command->ident->address, ident2->address);
    1.47 +    ASSERT_STRCASEEQ(il->next->command->ident->fpr, ident2->fpr);
    1.48 +    ASSERT_STREQ(il->next->command->ident->user_id, ident2->user_id);
    1.49 +    ASSERT_STREQ(il->next->command->ident->username, ident2->username);
    1.50 +    ASSERT_STREQ(il->next->command->new_key, key2);
    1.51 +
    1.52 +    ASSERT_EQ(il->next->next, nullptr);
    1.53 +
    1.54 +    // encode
    1.55 + 
    1.56 +    char *cmds = nullptr;
    1.57 +    size_t size = 0;
    1.58 +    PEP_STATUS status = key_reset_commands_to_PER(il, &cmds, &size);
    1.59 +    ASSERT_EQ(status, PEP_STATUS_OK);
    1.60 +    ASSERT_NE(cmds, nullptr);
    1.61 +    ASSERT_NE(size, 0);
    1.62 +
    1.63 +    // decode
    1.64 +    
    1.65 +    keyreset_command_list *ol = nullptr;
    1.66 +    status = PER_to_key_reset_commands(cmds, size, &ol);
    1.67 +    ASSERT_EQ(status, PEP_STATUS_OK);
    1.68 +    ASSERT_NE(ol, nullptr);
    1.69 +
    1.70 +    // compare
    1.71 +
    1.72 +    ASSERT_NE(ol->command, nullptr);
    1.73 +    ASSERT_NE(ol->command->ident, nullptr);
    1.74 +    ASSERT_NE(ol->command->new_key, nullptr);
    1.75 +
    1.76 +    ASSERT_STREQ(ol->command->ident->address, ident1->address);
    1.77 +    ASSERT_STRCASEEQ(ol->command->ident->fpr, ident1->fpr);
    1.78 +    ASSERT_STREQ(ol->command->ident->user_id, ident1->user_id);
    1.79 +    ASSERT_STREQ(ol->command->ident->username, ident1->username);
    1.80 +    ASSERT_STREQ(ol->command->new_key, key1);
    1.81 +
    1.82 +    ASSERT_NE(ol->next, nullptr);
    1.83 +    ASSERT_NE(ol->next->command, nullptr);
    1.84 +    ASSERT_NE(ol->next->command->ident, nullptr);
    1.85 +    ASSERT_NE(ol->next->command->new_key, nullptr);
    1.86 +
    1.87 +    ASSERT_STREQ(ol->next->command->ident->address, ident2->address);
    1.88 +    ASSERT_STRCASEEQ(ol->next->command->ident->fpr, ident2->fpr);
    1.89 +    ASSERT_STREQ(ol->next->command->ident->user_id, ident2->user_id);
    1.90 +    ASSERT_STREQ(ol->next->command->ident->username, ident2->username);
    1.91 +    ASSERT_STREQ(ol->next->command->new_key, key2);
    1.92 +
    1.93 +    ASSERT_EQ(ol->next->next, nullptr);
    1.94 +
    1.95 +    // free
    1.96 +
    1.97 +    free_keyreset_command_list(ol);
    1.98 +    free(cmds);
    1.99 +
   1.100 +    free_identity(ident1);
   1.101 +    free_identity(ident2);
   1.102 +    free_keyreset_command_list(il);
   1.103 +}