summaryrefslogtreecommitdiffstats
path: root/kwallet/backend/tests/backendtest.cpp
blob: c96fa42ce2866a80317bf55d71980b539a08240e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdlib.h>
#include <stdio.h>

#include <kapplication.h>
#include <kaboutdata.h>
#include <kcmdlineargs.h>
#include <tqstring.h>

#include "kwalletbackend.h"

#define CHECK_RETURN(func, test, test_str) { \
    int rc = (func); \
    test_cnt++;\
    if (test) {\
        printf("%-20s returned %d as expected  (should be %s)\n", #func, rc, test_str);\
    } else {\
        printf("%-20s returned %d UNEXPECTEDLY (should be %s)\n", #func, rc, test_str);\
        test_failed++;\
    }\
}

int main(int argc, char **argv) {
   KAboutData aboutData( "kwalletbackendtest", "kwallet backend testing routine", "0.1" );

   KCmdLineArgs::init( argc, argv, &aboutData );
   KApplication a(false, false);

   KWallet::Backend be("ktestwallet");
   printf("KWalletBackend constructed\n");

   TQByteArray apass, bpass, cpass;

   apass.duplicate("apassword", 9);
   bpass.duplicate("bpassword", 9);
   cpass.duplicate("cpassword", 9);


   int test_cnt = 0;
   int test_failed = 0;

   printf("Passwords initialised.\n");

   CHECK_RETURN(be.close(apass), rc==-255,       "-255");
   CHECK_RETURN(be.open(bpass),  rc==0 || rc==1, "0 or 1");
   CHECK_RETURN(be.close(bpass), rc==0,          "0 or 1");
   CHECK_RETURN(be.open(apass),  rc<0,           "negative");
   CHECK_RETURN(be.open(bpass),  rc==0,          "0");

   printf ("===========================================\n");
   printf ("%d test failed out of %d\n", test_failed, test_cnt);

   return test_failed == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}