pdf-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pdf-devel] fixing unit test issues - pdf_i64_div_005


From: Brad Hards
Subject: Re: [pdf-devel] fixing unit test issues - pdf_i64_div_005
Date: Sun, 14 Jun 2009 10:50:50 +1000
User-agent: KMail/1.9.10

On Sunday 14 June 2009 12:42:47 am Ɓukasz Spintzyk wrote:
> Hi actually I had fixed that. IN pdf-types.c ther schould be:
>
> line 569 :pdf_u32_t k, q_bar, n, z;
> line 570 :pdf_i32_t m;
>
> before *m* was pdf_u32_t, and that caused a problem.
>
>
> Please don't repair bugs in pdf_time module and in pdf_i64_div because i
> have alredy fixed them. I will commit them as soon as i will solve one
> doubt about pdf_time_from_string function.
OK. I do have some more bits already done. I'll post them here, and you can 
merge as appropriate.  Explanations lead patch, with "bradh:" to mark them.

bradh: Here is a cleanup that uses sprintf() format specifiers instead of 
hand-coding it.
=== modified file 'torture/unit/base/time/pdf-time-from-string.c'
--- torture/unit/base/time/pdf-time-from-string.c       2009-06-13 15:48:15 
+0000
+++ torture/unit/base/time/pdf-time-from-string.c       2009-06-14 00:21:31 
+0000
@@ -88,16 +88,11 @@                                                             
 
             offset_hours = (((gmt < 0) ? (-1) : (1)) * gmt) / 60;              
 
             offset_minutes = (((gmt < 0) ? (-1) : (1)) *gmt ) % 60;            
 
                                                                                
 
-            sprintf(&dateString[0],"%d-%s%d-%s%dT%s%d:%s%d:%s%d%c%s%d:%s%d",   
 
-                            dates[i].year,                                     
 
-                            (dates[i].month < 10 ? "0":""), dates[i].month,    
 
-                            (dates[i].day < 10 ? "0":""), dates[i].day,        
 
-                            (dates[i].hour < 10 ? "0":""), dates[i].hour,      
 
-                            (dates[i].minute < 10 ? "0":""), dates[i].minute,  
 
-                            (dates[i].second < 10 ? "0":""), dates[i].second,  
 
+            sprintf(&dateString[0],"%d-%02d-%02dT%02d:%02d:%02d%c%02d:%02d",   
 
+                            dates[i].year, dates[i].month, dates[i].day,       
 
+                            dates[i].hour, dates[i].minute, dates[i].second,   
 
                             ((gmt < 0) ? '-' : '+'),                           
 
-                            (offset_hours < 10 ? "0" : ""), offset_hours,      
 
-                            (offset_minutes < 10 ? "0" : ""), 
offset_minutes);  
+                            offset_hours, offset_minutes);                     
 
                                                                                
 
                                                                                
 
             status = pdf_time_from_string(time2,dateString, 
PDF_TIME_FORMAT_ISO_8601);
@@ -178,17 +173,16 @@                                                           
       
             offset_hours = (((gmt < 0) ? (-1) : (1)) * gmt) / 60;              
       
             offset_minutes = (((gmt < 0) ? (-1) : (1)) *gmt ) % 60;            
       
                                                                                
       
-            sprintf(&dateString[0],"%d-%s%d-%s%dT%s%d:%s%d%c%s%d:%s%d",        
       
-                            dates[i].year,                                     
       
-                            (dates[i].month < 10 ? "0":""), dates[i].month,    
       
-                            (dates[i].day < 10 ? "0":""), dates[i].day,        
       
-                            (dates[i].hour < 10 ? "0":""), dates[i].hour,      
       
-                            (dates[i].minute < 10 ? "0":""), dates[i].minute,  
       
+            sprintf(&dateString[0],"%d-%02d-%02dT%02d:%02d%c%02d:%02d",        
       
+                            dates[i].year, dates[i].month,                     
       
+                            dates[i].day, dates[i].hour,                       
       
+                            dates[i].minute,                                   
       
                             ((gmt < 0) ? '-' : '+'),                           
       
-                            (offset_hours < 10 ? "0" : ""), offset_hours,      
       
-                            (offset_minutes < 10 ? "0" : ""), 
offset_minutes);        
-                                                                               
       
-                                                                               
       
+                            offset_hours, offset_minutes);                     
       
+                                                                               
       
+            if(INTERACTIVE_DEBUG){                                             
       
+              printf("pdf_time_from_string_002: dateString: %s\n", 
dateString);       
+            }                                                                  
       
 /** Error in pdf_time_string which doesn't notice                              
       
  * that time is in format without seconds. */                                  
       
             status = pdf_time_from_string(time2,dateString, 
PDF_TIME_FORMAT_ISO_8601);
@@ -258,10 +252,8 @@                                                            
       
                                                                                
       
         pdf_time_set_from_u32(time1,seconds);                                  
       
                                                                                
       
-        sprintf(&dateString[0],"%d-%s%d-%s%d",                                 
       
-                      dates[i].year,                                           
       
-                     (dates[i].month < 10 ? "0":""), dates[i].month,           
       
-                     (dates[i].day < 10 ? "0":""), dates[i].day);              
       
+        sprintf(&dateString[0],"%d-%02d-%02d",                                 
       
+                      dates[i].year, dates[i].month, dates[i].day);            
       
                                                                                
       
                                                                                
       
         if (INTERACTIVE_DEBUG)                                                 
       
@@ -321,9 +313,7 @@                                                             
       
                                                                                
       
             pdf_time_set_from_u32(time1,seconds);                              
       
                                                                                
       
-            sprintf(&dateString[0],"%d-%s%d",                                  
       
-                            dates[i].year,                                     
       
-                            (dates[i].month < 10 ? "0":""), dates[i].month);   
       
+            sprintf(&dateString[0],"%d-%02d", dates[i].year, dates[i].month);  
       
                                                                                
       
                                                                                
       
  /**                                                                           
       
@@ -477,16 +467,11 @@                                                           
       
             offset_hours = (((gmt < 0) ? (-1) : (1)) * gmt) / 60;              
       
             offset_minutes = (((gmt < 0) ? (-1) : (1)) *gmt ) % 60;            
       
                                                                                
       
-            sprintf(&dateString[0],"D:%d%s%d%s%d%s%d%s%d%s%d%c%s%d'%s%d'",     
       
-                            dates[i].year,                                     
       
-                            (dates[i].month < 10 ? "0":""), dates[i].month,    
       
-                            (dates[i].day < 10 ? "0":""), dates[i].day,        
       
-                            (dates[i].hour < 10 ? "0":""), dates[i].hour,      
       
-                            (dates[i].minute < 10 ? "0":""), dates[i].minute,  
       
-                            (dates[i].second < 10 ? "0":""), dates[i].second,  
       
+            sprintf(&dateString[0],"D:%d%02d%02d%02d%02d%02d%c%02d'%02d'",     
       
+                            dates[i].year, dates[i].month, dates[i].day,       
       
+                            dates[i].hour, dates[i].minute, dates[i].second,   
       
                             ((gmt < 0) ? '-' : '+'),                           
       
-                            (offset_hours < 10 ? "0" : ""), offset_hours,      
       
-                            (offset_minutes < 10 ? "0" : ""), 
offset_minutes);        
+                            offset_hours, offset_minutes);                     
       
                                                                                
       
                                                                                
       
             fail_if(PDF_OK != PDF_OK);                                         
       
@@ -593,16 +578,11 @@                                                           
       
             offset_hours = (((gmt < 0) ? (-1) : (1)) * gmt) / 60;              
       
             offset_minutes = (((gmt < 0) ? (-1) : (1)) *gmt ) % 60;            
       
                                                                                
       
-            sprintf(&dateString[0],"%d%s%d%s%d%s%d%s%d%s%d%c%s%d%s%d",         
       
-                            dates[i].year,                                     
       
-                            (dates[i].month < 10 ? "0":""), dates[i].month,    
       
-                            (dates[i].day < 10 ? "0":""), dates[i].day,        
       
-                            (dates[i].hour < 10 ? "0":""), dates[i].hour,      
       
-                            (dates[i].minute < 10 ? "0":""), dates[i].minute,  
       
-                            (dates[i].second < 10 ? "0":""), dates[i].second,  
       
+            sprintf(&dateString[0],"%d%02d%02d%02d%02d%02d%c%02d%02d",         
       
+                            dates[i].year, dates[i].month, dates[i].day,       
       
+                            dates[i].hour, dates[i].minute, dates[i].second,   
       
                             ((gmt < 0) ? '-' : '+'),                           
       
-                            (offset_hours < 10 ? "0" : ""), offset_hours,      
       
-                            (offset_minutes < 10 ? "0" : ""), 
offset_minutes);        
+                            offset_hours, offset_minutes);                     
       
                                                                                
       
                                                                                
       
             status = pdf_time_from_string(time2,dateString, 
PDF_TIME_FORMAT_GENERALIZED_ASN1);
@@ -683,15 +663,11 @@                                                           
               
             offset_hours = (((gmt < 0) ? (-1) : (1)) * gmt) / 60;              
               
             offset_minutes = (((gmt < 0) ? (-1) : (1)) *gmt ) % 60;            
               
                                                                                
               
-            sprintf(&dateString[0],"%d%s%d%s%d%s%d%s%d%c%s%d%s%d",             
               
-                            dates[i].year,                                     
               
-                            (dates[i].month < 10 ? "0":""), dates[i].month,    
               
-                            (dates[i].day < 10 ? "0":""), dates[i].day,        
               
-                            (dates[i].hour < 10 ? "0":""), dates[i].hour,      
               
-                            (dates[i].minute < 10 ? "0":""), dates[i].minute,  
               
+            sprintf(&dateString[0],"%d%02d%02d%02d%02d%c%02d%02d",             
               
+                            dates[i].year, dates[i].month, dates[i].day,       
               
+                            dates[i].hour, dates[i].minute,                    
               
                             ((gmt < 0) ? '-' : '+'),                           
               
-                            (offset_hours < 10 ? "0" : ""), offset_hours,      
               
-                            (offset_minutes < 10 ? "0" : ""), 
offset_minutes);                
+                            offset_hours, offset_minutes);                     
               
                                                                                
               
                                                                                
               
             status = pdf_time_from_string(time2,dateString, 
PDF_TIME_FORMAT_GENERALIZED_ASN1);
@@ -763,10 +739,8 @@                                                            
               
                                                                                
               
     pdf_time_set_from_u32(time1,seconds);                                      
               
                                                                                
               
-    sprintf(&dateString[0],"%d%s%d%s%d",                                       
               
-            dates[i].year,                                                     
               
-            (dates[i].month < 10 ? "0":""), dates[i].month,                    
               
-            (dates[i].day < 10 ? "0":""), dates[i].day);                       
               
+    sprintf(&dateString[0],"%d%02d%02d",                                       
               
+            dates[i].year, dates[i].month, dates[i].day);                      
               
                                                                                
               
                                                                                
               
      status = pdf_time_from_string(time2,dateString, 
PDF_TIME_FORMAT_GENERALIZED_ASN1);       
@@ -825,9 +799,7 @@                                                             
               
                                                                                
               
         pdf_time_set_from_u32(time1,seconds);                                  
               
                                                                                
               
-        sprintf(&dateString[0],"%d%s%d",                                       
               
-                      dates[i].year,                                           
               
-                     (dates[i].month < 10 ? "0":""), dates[i].month);          
               
+        sprintf(&dateString[0],"%d%02d", dates[i].year, dates[i].month);       
               
                                                                                
               
                                                                                
               
  /**                                                                           
               



bradh: Here is a bit where the description is wrong - there is no comparison.
Also, the test doesn't check for NULL pointer.
=== modified file 'torture/unit/base/time/pdf-time-span-copy.c'
--- torture/unit/base/time/pdf-time-span-copy.c 2009-05-07 10:31:42 +0000
+++ torture/unit/base/time/pdf-time-span-copy.c 2009-06-13 11:26:30 +0000
@@ -71,20 +71,20 @@                                                      
  *Success condition:                                                    
  * 1. Function pdf_time_span_copy schould return                        
  * PDF_ERROR.                                                           
- * 2. Function pdf_time_span_cmp schould return 0                       
- * (objects must be equal).                                             
  */                                                                     
 START_TEST (pdf_time_span_copy_002)                                     
 {                                                                       
   pdf_status_t status;                                                  
   pdf_time_span_t span1;                                                
-  pdf_time_span_t span2;                                                
+  pdf_time_span_t *span2;                                               
                                                                         
   span1 = pdf_time_span_new();                                          
                                                                         
   pdf_time_span_set(&span1,0x01234567,0x89ABCDEF);                      
                                                                         
-  status = pdf_time_span_copy(span1, &span2);                           
+  span2 = NULL;                                                         
+                                                                        
+  status = pdf_time_span_copy(span1, span2);                            
   fail_if(status != PDF_ERROR);                                         

   status = pdf_time_span_destroy(&span1);


bradh: pass pointer, not structure.
=== modified file 'torture/unit/base/time/pdf-time-span-destroy.c'
--- torture/unit/base/time/pdf-time-span-destroy.c      2009-04-16 22:13:38 
+0000
+++ torture/unit/base/time/pdf-time-span-destroy.c      2009-05-26 07:55:21 
+0000
@@ -48,7 +48,7 @@
   sec = pdf_time_span_to_secs(span);
   sec2 = pdf_i64_new(0, 0);

-  fail_unless(memcmp(sec, sec2, sizeof(pdf_i64_t)) == 0);
+  fail_unless(memcmp(&sec, &sec2, sizeof(pdf_i64_t)) == 0);

   status = pdf_time_span_destroy(&span);
   fail_if(status != PDF_OK);


bradh: description is wrong (and has typo). need to pass a null pointer to 
make the test work.
=== modified file 'torture/unit/base/time/pdf-time-span-negate.c'
--- torture/unit/base/time/pdf-time-span-negate.c       2009-05-07 10:31:42 
+0000
+++ torture/unit/base/time/pdf-time-span-negate.c       2009-06-13 10:25:52 
+0000
@@ -102,15 +102,14 @@
  *   Try to get invoke pdf_time_span_negate where
  *   argument pointer is NUL.
  *Success condition:
- * 1. Function pdf_time_span_new schould return PDF_OK
- * 2. Function pdf_time_span_negate schould return PDF_ERROR
+ * 1. Function pdf_time_span_negate should return PDF_ERROR
  */
 START_TEST (pdf_time_span_negate_003)
 {
     pdf_status_t status;
-    pdf_time_span_t span;
-
-    status = pdf_time_span_negate(&span);
+    pdf_time_span_t *span = 0;
+
+    status = pdf_time_span_negate(span);
     fail_if(status != PDF_ERROR);

 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]