Commit 6f5bec4f authored by Thomas Guillem's avatar Thomas Guillem

test: fix keystore test suite

- Create a libvlc instance, in order to init the module bank, before testing if
  modules exist.
- Use mkstemp to create a unique temporary file used by plaintext
- Don't test secret and kwallet by default in order to don't pollute
  developer's keystores (run this test with "-a" argv to test every keystores).
parent 7f575521
...@@ -33,29 +33,17 @@ ...@@ -33,29 +33,17 @@
#include <assert.h> #include <assert.h>
#define PLAINTEXT_TEST_FILE "/tmp/vlc.test.keystore"
/* If 1, tester will have time to check keystore entries via an external
* program */
#define LET_CHECK_VALUES 0
static const struct static const struct
{ {
const char *psz_module; const char *psz_module;
int argc; bool b_test_default;
const char * const *argv;
} keystore_args[] = } keystore_args[] =
{ {
{ "plaintext", 2, (const char *[]) { { "plaintext", true },
"--keystore=plaintext,none", /* Following keystores are tested only when asked explicitly by the tester
"--keystore-plaintext-file=" PLAINTEXT_TEST_FILE * (with "-a" argv) */
} }, { "secret", false },
{ "secret", 1, (const char *[]) { { "kwallet", false }
"--keystore=secret,none"
} },
{ "kwallet", 1, (const char *[]) {
"--keystore=kwallet,none"
} },
}; };
static void static void
...@@ -109,7 +97,8 @@ ks_store(vlc_keystore *p_keystore, const char *const ppsz_values[KEY_MAX], ...@@ -109,7 +97,8 @@ ks_store(vlc_keystore *p_keystore, const char *const ppsz_values[KEY_MAX],
} }
static void static void
test_module(const char *psz_module, int argc, const char * const *argv) test_module(const char *psz_module, bool b_test_all,
int argc, const char * const *argv)
{ {
#define VALUES_INSERT(i_key, psz_value) ppsz_values[i_key] = psz_value #define VALUES_INSERT(i_key, psz_value) ppsz_values[i_key] = psz_value
#define VALUES_REINIT() values_reinit(ppsz_values) #define VALUES_REINIT() values_reinit(ppsz_values)
...@@ -127,10 +116,6 @@ test_module(const char *psz_module, int argc, const char * const *argv) ...@@ -127,10 +116,6 @@ test_module(const char *psz_module, int argc, const char * const *argv)
libvlc_instance_t *p_libvlc = libvlc_new(argc, argv); libvlc_instance_t *p_libvlc = libvlc_new(argc, argv);
assert(p_libvlc != NULL); assert(p_libvlc != NULL);
/* See TODO in kwallet.cpp, VLCKWallet::connect() */
if (strcmp(psz_module, "kwallet") == 0)
assert(libvlc_InternalAddIntf(p_libvlc->p_libvlc_int, "qt") == VLC_SUCCESS);
vlc_interrupt_t *ctx = vlc_interrupt_create(); vlc_interrupt_t *ctx = vlc_interrupt_create();
assert(ctx != NULL); assert(ctx != NULL);
...@@ -235,10 +220,11 @@ test_module(const char *psz_module, int argc, const char * const *argv) ...@@ -235,10 +220,11 @@ test_module(const char *psz_module, int argc, const char * const *argv)
KS_FIND(); KS_FIND();
assert(i_entries == 4); assert(i_entries == 4);
#if LET_CHECK_VALUES if (b_test_all)
{
printf("\nPress ENTER to remove entries\n"); printf("\nPress ENTER to remove entries\n");
getchar(); getchar();
#endif }
printf("testing removing entries that match user => user1\n"); printf("testing removing entries that match user => user1\n");
VALUES_REINIT(); VALUES_REINIT();
...@@ -270,27 +256,64 @@ test_module(const char *psz_module, int argc, const char * const *argv) ...@@ -270,27 +256,64 @@ test_module(const char *psz_module, int argc, const char * const *argv)
} }
int int
main(void) main(int i_argc, char *ppsz_argv[])
{ {
#if !LET_CHECK_VALUES /* If b_test_all is true, this test could pollute the developer´s keystores */
alarm(10); bool b_test_all = i_argc > 1 && strcmp(ppsz_argv[1], "-a") == 0;
#endif
if (!b_test_all)
alarm(3);
setenv("VLC_PLUGIN_PATH", "../modules", 1); setenv("VLC_PLUGIN_PATH", "../modules", 1);
unlink(PLAINTEXT_TEST_FILE);
/* Create a dummy libvlc to initialize module bank, needed by module_exists */
libvlc_instance_t *p_libvlc = libvlc_new(0, NULL);
assert(p_libvlc != NULL);
for (unsigned int i = 0; i < sizeof(keystore_args)/sizeof(*keystore_args); ++i) for (unsigned int i = 0; i < sizeof(keystore_args)/sizeof(*keystore_args); ++i)
{ {
const char *psz_module = keystore_args[i].psz_module; const char *psz_module = keystore_args[i].psz_module;
int argc = keystore_args[i].argc;
const char * const *argv = keystore_args[i].argv;
if (module_exists(psz_module)) if ((b_test_all || keystore_args[i].b_test_default)
test_module(psz_module, argc, argv); && module_exists(psz_module))
{
int i_vlc_argc = 1;
char *ppsz_vlc_argv[2] = { 0 };
int i_tmp_fd = -1;
char psz_tmp_path[] = "/tmp/libvlc_XXXXXX";
assert(asprintf(&ppsz_vlc_argv[0], "--keystore=%s,none",
psz_module) != -1);
if (strcmp(psz_module, "plaintext") == 0)
{
assert((i_tmp_fd = mkstemp(psz_tmp_path)) != -1);
printf("plaintext tmp file: '%s'\n", psz_tmp_path);
assert(asprintf(&ppsz_vlc_argv[1],
"--keystore-plaintext-file=%s", psz_tmp_path) != -1);
i_vlc_argc++;
}
else if (strcmp(psz_module, "kwallet") == 0)
{
/* See TODO in kwallet.cpp, VLCKWallet::connect() */
assert(libvlc_InternalAddIntf(p_libvlc->p_libvlc_int, "qt") == VLC_SUCCESS);
}
test_module(psz_module, b_test_all, i_vlc_argc,
(const char * const *)ppsz_vlc_argv);
if (i_tmp_fd != -1)
{
close(i_tmp_fd);
unlink(psz_tmp_path);
}
free(ppsz_vlc_argv[0]);
free(ppsz_vlc_argv[1]);
}
else else
printf("not testing %s since the plugin is not found\n", psz_module); printf("not testing %s\n", psz_module);
} }
unlink(PLAINTEXT_TEST_FILE); libvlc_release(p_libvlc);
return 0; return 0;
} }
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