embedded IPsec source code documentation


util_test.c

Go to the documentation of this file.
00001 /*
00002  * embedded IPsec
00003  * Copyright (c) 2003 Niklaus Schild and Christian Scheurer, HTI Biel/Bienne
00004  * All rights reserved.
00005  *
00006  * Redistribution and use in source and binary forms, with or without modification,
00007  * are permitted provided that the following conditions are met:
00008  *
00009  * 1. Redistributions of source code must retain the above copyright notice,
00010  *    this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright notice,
00012  *    this list of conditions and the following disclaimer in the documentation
00013  *    and/or other materials provided with the distribution.
00014  * 3. The name of the author may not be used to endorse or promote products
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00018  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00020  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00021  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00022  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00025  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00026  * OF SUCH DAMAGE.
00027  *
00028  */
00029 
00050 #include <string.h>
00051 
00052 #include "ipsec/util.h"
00053 #include "ipsec/debug.h"
00054 #include "testing/structural/structural_test.h"
00055 
00059 int test_ipsec_inet_addr(void)
00060 {
00061         int                     local_error_count = 0 ;
00062         unsigned long   ipsec_inet_address ;
00063 
00064         ipsec_inet_address = ipsec_inet_addr("192.168.100.100") ;
00065         if(ipsec_inet_address != 0x6464A8C0)
00066         {
00067                 local_error_count++ ;
00068                 IPSEC_LOG_TST("test_ipsec_inet_addr", "FAILURE", ("192.168.100.100 was not properly converted to network order")) ;
00069         }
00070 
00071         ipsec_inet_address = ipsec_inet_addr("255.255.255.255") ;
00072         if(ipsec_inet_address != 0xFFFFFFFF)
00073         {
00074                 local_error_count++ ;
00075                 IPSEC_LOG_TST("test_ipsec_inet_addr", "FAILURE", ("255.255.255.255 was not properly converted to network order")) ;
00076         }
00077 
00078 
00079         ipsec_inet_address = ipsec_inet_addr("255.0.0.0") ;
00080         if(ipsec_inet_address != 0x000000FF)
00081         {
00082                 local_error_count++ ;
00083                 IPSEC_LOG_TST("test_ipsec_inet_addr", "FAILURE", ("255.255.0.0 was not properly converted to network order")) ;
00084         }
00085 
00086 
00087         ipsec_inet_address = ipsec_inet_addr("192.168.1.2") ;
00088         if(ipsec_inet_address != 0x0201A8C0)
00089         {
00090                 local_error_count++ ;
00091                 IPSEC_LOG_TST("test_ipsec_inet_addr", "FAILURE", ("192.168.1.2 was not properly converted to network order")) ;
00092         }
00093 
00094 
00095         ipsec_inet_address = ipsec_inet_addr("1.2.3.4") ;
00096         if(ipsec_inet_address != 0x04030201)
00097         {
00098                 local_error_count++ ;
00099                 IPSEC_LOG_TST("test_ipsec_inet_addr", "FAILURE", ("1.2.3.4 was not properly converted to network order")) ;
00100         }
00101 
00102 
00103         ipsec_inet_address = ipsec_inet_addr("1.2.3.100") ;
00104         if(ipsec_inet_address != 0x64030201)
00105         {
00106                 local_error_count++ ;
00107                 IPSEC_LOG_TST("test_ipsec_inet_addr", "FAILURE", ("1.2.3.100 was not properly converted to network order")) ;
00108         }       
00109 
00110         return local_error_count ;
00111 }
00112 
00117 void util_debug_test(test_result *global_results)
00118 {
00119         test_result     sub_results     = {
00120                                                   6,                    
00121                                                   1,                    
00122                                                   0,            
00123                                                   0,    
00124                                         };
00125 
00126         int retcode;
00127 
00128         /*
00129         IPSEC_LOG_DBG("ipsec_esp_encapsulate", 0, "EN") ;
00130 
00131         IPSEC_LOG_ERR("ipsec_esp_encapsulate", -5, "was not able to encapsulate the ESP packet because of invalid packet header") ;
00132         IPSEC_LOG_ERR("ipsec_md5_check", -5000, "failled due to bad function pointer") ;
00133 
00134         IPSEC_LOG_MSG("ipsec_esp_encapsulate", "the cause of the previous error may be a bug in the HW device driver") ;
00135 
00136         IPSEC_LOG_AUD("ipsec_esp_decapsulate", -1050, "datagram could not be decapsulated because it is not valid") ;
00137 
00138         IPSEC_LOG_DBG("ipsec_esp_encapsulate", 0, "EX") ;       
00139 
00140         IPSEC_LOG_TST("test_debug", 0, "if the above printed messages appear nicely, then it works fine!") ;
00141         */
00142 
00143         IPSEC_LOG_TST("test_debug", "NOTE", ("These text printing macros have no particular test"));
00144 
00145         retcode = test_ipsec_inet_addr() ;
00146         IPSEC_TESTING_EVALUATE(retcode, sub_results, "test_util_ipsec_inet_addr()", (" "));
00147 
00148 
00149 
00150         global_results->tests += sub_results.tests;
00151         global_results->functions += sub_results.functions;
00152         global_results->errors += sub_results.errors;
00153         global_results->notimplemented += sub_results.notimplemented;
00154 }
00155 
00156 
00157 
00158 
00159 

Copyright 2003 by Christian Scheurer and Niklaus Schild