1 /*----------------------------------------------------------------------------
 2 Name:      xmlBlaster/testsuite/src/c/TestSocket.c
 3 Project:   xmlBlaster.org
 4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
 5 Comment:   Test C client library
 6 Author:    "Marcel Ruff" <xmlBlaster@marcelruff.info>
 7 Compile:   cd xmlBlaster; build c
 8 Invoke:    'TestSocket'
 9 See:       http://www.xmlblaster.org/xmlBlaster/doc/requirements/c.client.socket.html
10 -----------------------------------------------------------------------------*/
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <util/helper.h>
15 #include <socket/xmlBlasterSocket.h>
16 #include "test.h"
17 
18 static const char * test_exceptionEncode()
19 {
20    XmlBlasterException exception, exceptionAfter;
21    XmlBlasterBlob blob;
22 
23    {
24       initializeXmlBlasterException(&exception);
25 
26       encodeXmlBlasterException(&blob, &exception, true);
27 
28       convertToXmlBlasterException(&blob, &exceptionAfter, true);
29 
30       freeBlobHolderContent(&blob);
31 
32       mu_assertEqualsString("Exception encoding failed", exception.errorCode, exceptionAfter.errorCode);
33       mu_assertEqualsString("Exception encoding failed", exception.message, exceptionAfter.message);
34       mu_assertEqualsBool("Exception encoding failed", true, exceptionAfter.remote);
35    }
36    {
37       initializeXmlBlasterException(&exception);
38       strncpy0(exception.errorCode, "communication.noConnection", XMLBLASTEREXCEPTION_ERRORCODE_LEN);
39       SNPRINTF(exception.message, XMLBLASTEREXCEPTION_MESSAGE_LEN,
40                      "[%.100s:%d] Lost connection to xmlBlaster with server side EOF", __FILE__, __LINE__);
41 
42       encodeXmlBlasterException(&blob, &exception, true);
43 
44       convertToXmlBlasterException(&blob, &exceptionAfter, true);
45 
46       freeBlobHolderContent(&blob);
47 
48       mu_assertEqualsString("Exception encoding failed", exception.errorCode, exceptionAfter.errorCode);
49       mu_assertEqualsString("Exception encoding failed", exception.message, exceptionAfter.message);
50       mu_assertEqualsBool("Exception encoding failed", true, exceptionAfter.remote);
51    }
52    return 0;
53 }
54 
55 static const char *all_tests()
56 {
57    mu_run_test(test_exceptionEncode);
58    return 0;
59 }
60 
61 /**
62  * exit(0) if OK
63  */
64 int main(int argc_, char **argv_)
65 {
66    const char *result;
67 
68    result = all_tests();
69 
70    if (result != 0) {
71       printf("[TEST FAIL] %s\n", result);
72    }
73    else {
74       printf("ALL %d TESTS PASSED\n", tests_run);
75    }
76    printf("Tests run: %d\n", tests_run);
77 
78    return result != 0;
79 }


syntax highlighted by Code2HTML, v. 0.9.1