[prev in list] [next in list] [prev in thread] [next in thread] 

List:       expat-cvs
Subject:    [Expat-checkins] CVS: expat/tests chardata.c,1.1,1.2
From:       "Fred L. Drake" <fdrake () users ! sourceforge ! net>
Date:       2002-04-29 17:09:35
[Download RAW message or body]

Update of /cvsroot/expat/expat/tests
In directory usw-pr-cvs1:/tmp/cvs-serv20845/tests

Modified Files:
	chardata.c 
Log Message:
Added a bunch of assertions that internal assumptions are not violated
(specifically, make sure args are not NULL).

If the expected value is not the right length, include the value found in
the error message, to make problems easier to diagnose.


Index: chardata.c
===================================================================
RCS file: /cvsroot/expat/expat/tests/chardata.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** chardata.c	25 Apr 2002 04:04:42 -0000	1.1
--- chardata.c	29 Apr 2002 17:09:31 -0000	1.2
***************
*** 4,7 ****
--- 4,8 ----
   */
  
+ #include <assert.h>
  #include <check.h>
  #include <stdio.h>
***************
*** 14,17 ****
--- 15,19 ----
  xmlstrlen(const XML_Char *s)
  {
+     assert(s != NULL);
      int len = 0;
      while (s[len] != 0)
***************
*** 24,27 ****
--- 26,30 ----
  CharData_Init(CharData *storage)
  {
+     assert(storage != NULL);
      storage->count = -1;
  }
***************
*** 31,36 ****
  {
      int maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
!     int len = strlen(s);
  
      if (storage->count < 0)
          storage->count = 0;
--- 34,41 ----
  {
      int maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
!     int len;
  
+     assert(s != NULL);
+     len = strlen(s);
      if (storage->count < 0)
          storage->count = 0;
***************
*** 47,52 ****
  CharData_AppendXMLChars(CharData *storage, const XML_Char *s, int len)
  {
!     int maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
  
      if (storage->count < 0)
          storage->count = 0;
--- 52,60 ----
  CharData_AppendXMLChars(CharData *storage, const XML_Char *s, int len)
  {
!     int maxchars;
  
+     assert(storage != NULL);
+     assert(s != NULL);
+     maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
      if (storage->count < 0)
          storage->count = 0;
***************
*** 66,76 ****
  CharData_CheckString(CharData *storage, const char *expected)
  {
!     char buffer[1024];
!     int len = strlen(expected);
!     int count = (storage->count < 0) ? 0 : storage->count;
  
      if (len != count) {
!         sprintf(buffer, "wrong number of data characters: got %d, expected %d",
!                 count, len);
          fail(buffer);
          return false;
--- 74,93 ----
  CharData_CheckString(CharData *storage, const char *expected)
  {
!     char buffer[1280];
!     int len;
!     int count;
  
+     assert(storage != NULL);
+     assert(expected != NULL);
+     count = (storage->count < 0) ? 0 : storage->count;
+     len = strlen(expected);
      if (len != count) {
!         if (sizeof(XML_Char) == 1)
!             sprintf(buffer, "wrong number of data characters:"
!                     " got %d, expected %d:\n%s", count, len, storage->data);
!         else
!             sprintf(buffer,
!                     "wrong number of data characters: got %d, expected %d",
!                     count, len);
          fail(buffer);
          return false;
***************
*** 87,93 ****
  {
      char buffer[1024];
!     int len = strlen(expected);
!     int count = (storage->count < 0) ? 0 : storage->count;
  
      if (len != count) {
          sprintf(buffer, "wrong number of data characters: got %d, expected %d",
--- 104,112 ----
  {
      char buffer[1024];
!     int len = xmlstrlen(expected);
!     int count;
  
+     assert(storage != NULL);
+     count = (storage->count < 0) ? 0 : storage->count;
      if (len != count) {
          sprintf(buffer, "wrong number of data characters: got %d, expected %d",


_______________________________________________
Expat-checkins mailing list
Expat-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/expat-checkins
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic