Commit 3692c080 authored by johan's avatar johan

Add simple cache migration test

- todo: improve it
parent d4cbbbe0
......@@ -69,6 +69,7 @@ test_suite_t packet_parser_test_suite = {
test_t zidcache_tests[] = {
TEST_NO_TAG("SelfZID", test_cache_getSelfZID),
TEST_NO_TAG("ZRTP secrets", test_cache_zrtpSecrets),
TEST_NO_TAG("Migration", test_cache_migration),
};
test_suite_t zidcache_test_suite = {
......
......@@ -28,8 +28,16 @@
#include "testUtils.h"
#include "zidCache.h"
#ifdef ZIDCACHE_ENABLED
#include "sqlite3.h"
#ifdef HAVE_LIBXML2
#include <libxml/tree.h>
#include <libxml/parser.h>
#endif /* HAVE_LIBXML2 */
#endif /* ZIDCACHE_ENABLED */
static const char *xmlCacheMigration = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<cache><selfZID>00112233445566778899aabb</selfZID><peer><ZID>99887766554433221100ffee</ZID><rs1>c4274f13a2b6fa05c15ec93158f930e7264b0a893393376dbc80c6eb1cccdc5a</rs1><uri>sip:bob@sip.linphone.org</uri><sndKey>219d9e445d10d4ed64083c7ccbb83a23bc17a97df0af5de4261f3fe026b05b0b</sndKey><rcvKey>747e72a5cc996413cb9fa6e3d18d8b370436e274cd6ba4efc1a4580340af57ca</rcvKey><sndSId>df2bf38e719fa89e17332cf8d5e774ee70d347baa74d16dee01f306c54789869</sndSId><rcvSId>928ce78b0bfc30427a02b1b668b2b3b0496d5664d7e89b75ed292ee97e3fc850</rcvSId><sndIndex>496bcc89</sndIndex><rcvIndex>59337abe</rcvIndex><rs2>5dda11f388384b349d210612f30824268a3753a7afa52ef6df5866dca76315c4</rs2><uri>sip:bob2@sip.linphone.org</uri></peer><peer><ZID>ffeeddccbbaa987654321012</ZID><rs1>858b495dfad483af3c088f26d68c4beebc638bd44feae45aea726a771727235e</rs1><uri>sip:bob@sip.linphone.org</uri><sndKey>b6aac945057bc4466bfe9a23771c6a1b3b8d72ec3e7d8f30ed63cbc5a9479a25</sndKey><rcvKey>bea5ac3225edd0545b816f061a8190370e3ee5160e75404846a34d1580e0c263</rcvKey><sndSId>17ce70fdf12e500294bcb5f2ffef53096761bb1c912b21e972ae03a5a9f05c47</sndSId><rcvSId>7e13a20e15a517700f0be0921f74b96d4b4a0c539d5e14d5cdd8706441874ac0</rcvSId><sndIndex>75e18caa</sndIndex><rcvIndex>2cfbbf06</rcvIndex><rs2>1533dee20c8116dc2c282cae9adfea689b87bc4c6a4e18a846f12e3e7fea3959</rs2></peer><peer><ZID>0987654321fedcba5a5a5a5a</ZID><rs1>cb6ecc87d1dd87b23f225eec53a26fc541384917623e0c46abab8c0350c6929e</rs1><sndKey>92bb03988e8f0ccfefa37a55fd7c5893bea3bfbb27312f49dd9b10d0e3c15fc7</sndKey><rcvKey>2315705a5830b98f68458fcd49623144cb34a667512c4d44686aee125bb8b622</rcvKey><sndSId>94c56eea0dd829379263b6da3f6ac0a95388090f168a3568736ca0bd9f8d595f</sndSId><rcvSId>c319ae0d41183fec90afc412d42253c5b456580f7a463c111c7293623b8631f4</rcvSId><uri>sip:bob@sip.linphone.org</uri><sndIndex>2c46ddcc</sndIndex><rcvIndex>15f5779e</rcvIndex><valid>0000000058f095bf</valid><pvs>01</pvs></peer></cache>";
void test_cache_getSelfZID(void) {
#ifdef ZIDCACHE_ENABLED
......@@ -188,3 +196,34 @@ void test_cache_zrtpSecrets(void) {
bzrtp_message("Test skipped as ZID cache is disabled\n");
#endif /* ZIDCACHE_ENABLED */
}
void test_cache_migration(void) {
#ifdef ZIDCACHE_ENABLED
uint8_t pattern_selfZIDalice[12] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb};
uint8_t selfZIDalice[12];
sqlite3 *aliceDB=NULL;
/* Parse the xmlCache */
xmlDocPtr cacheXml = xmlParseDoc((xmlChar*)xmlCacheMigration);
/* create a new DB file */
remove("tmpZIDAlice.sqlite");
bzrtptester_sqlite3_open(bc_tester_file("tmpZIDAlice.sqlite"), &aliceDB);
BC_ASSERT_EQUAL(bzrtp_initCache((void *)aliceDB), BZRTP_CACHE_SETUP, int, "%x");
/* perform migration */
BC_ASSERT_EQUAL(bzrtp_cache_migration((void *)cacheXml, (void *)aliceDB, "sip:alice@sip.linphone.org"), 0, int, "%x");
/* check values in new cache */
BC_ASSERT_EQUAL(bzrtp_getSelfZID(aliceDB, "sip:alice@sip.linphone.org", selfZIDalice, NULL), 0, int, "%x");
BC_ASSERT_EQUAL(memcmp(pattern_selfZIDalice, selfZIDalice, 12), 0, int, "%d");
/* TODO: read values from sql cache lime and zrtp tables and check they are the expected ones */
/* cleaning */
sqlite3_close(aliceDB);
xmlFree(cacheXml);
#else /* ZIDCACHE_ENABLED */
bzrtp_message("Test skipped as ZID cache is disabled\n");
#endif /* ZIDCACHE_ENABLED */
}
......@@ -21,3 +21,4 @@
*/
void test_cache_getSelfZID(void);
void test_cache_zrtpSecrets(void);
void test_cache_migration(void);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment