ESAPI-C 1.0
The OWASP Enterprise Security API for C

test/src/properties_test.c

Go to the documentation of this file.
00001 /*
00002  * properties_test.c
00003  *
00004  */
00005 
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009 
00010 #include "minunit.h"
00011 #include "properties.h"
00012 #include "crypto.h"
00013 
00014 int tests_run = 0;
00015 
00016 void test_set_property(struct esapi_ctx *ctx) {
00017 
00018         // Initialize/clear properties
00019         map_t *map = NULL;
00020         (void)fprintf(stdout, "Size of map_t = %lu\n", sizeof(map_t));
00021         (void)fprintf(stdout, "Testing %s\n", __func__);
00022         TEST(set_property(&map, ctx, "foreground color", "yellow") != NULL);
00023 }
00024 
00025 void test_get_property(struct esapi_ctx *ctx) {
00026 
00027         // Initialize/clear properties
00028         map_t *map = NULL;
00029         (void)fprintf(stdout, "Testing %s\n", __func__);
00030         set_property(&map, ctx, "foreground color", "yellow");
00031         TEST(get_property(map, ctx, "foreground color") != 0);
00032         TEST(strcmp(get_property(map, ctx, "foreground color"), "yellow") == 0);
00033         TEST(get_property(map, ctx, "background color") == 0);
00034 }
00035 
00036 void test_store_properties(struct esapi_ctx *ctx) {
00037         // Initialize/clear properties
00038         map_t *map;
00039         (void)fprintf(stdout, "Testing %s\n", __func__);
00040         set_property(&map, ctx, "foreground color", "yellow");
00041         store_properties(map, "../configuration/encrypted.properties");
00042         // FIXME: What test?
00043 }
00044 
00045 
00046 void test_load_properties(struct esapi_ctx *ctx) {
00047         map_t *map = load_properties("../configuration/encrypted.properties");
00048         (void)fprintf(stdout, "Testing %s\n", __func__);
00049         TEST(get_property(map, ctx, "foreground color") != 0);
00050         TEST(strcmp(get_property(map, ctx, "foreground color"), "yellow") == 0);
00051 }
00052 
00053 
00054 int main(int argc, char **argv) {
00055         printf("Running unit test %s\n", argv[0]);
00056 
00057         struct esapi_ctx *ctx = load_security_context("../configuration/ESAPI.properties");
00058         esapi_crypto_init();
00059 
00060 //      char *plaintext = "yellow";
00061 //      char *encrypted_value = esapi_encrypt(ctx, plaintext);
00062 //      (void)fprintf(stdout, "%s: Encrypted %s to %s\n", __FILE__, plaintext, encrypted_value);
00063 //      char *decrypted_value = esapi_decrypt(ctx, encrypted_value);
00064 //      (void)fprintf(stdout, "%s: Decrypted to %s\n", __FILE__, decrypted_value);
00065 
00066         test_set_property(ctx);
00067         test_get_property(ctx);
00068         test_store_properties(ctx);
00069         test_load_properties(ctx);
00070 
00071         (void)fprintf(stdout, "%s: Pass <%i>, Fail<%i>\n", __FILE__, passed, failed);
00072         return(EXIT_SUCCESS);
00073 }
 All Data Structures Files Functions Variables Typedefs Defines