Bug 1402151, part 8 - Add an argument to ParseFTPList to return the current time. r=michal draft
authorAndrew McCreight <continuation@gmail.com>
Mon, 25 Sep 2017 13:27:09 -0700
changeset 680198 6a39a32f1cc64b10466a12044d97680ec07ecabb
parent 680197 a9149aa36295316231d9e2987cf45deca9cf962e
child 680199 71af3ee22aecc57de640a54f5b7c269a23f14883
push id84417
push userbmo:continuation@gmail.com
push dateFri, 13 Oct 2017 16:41:48 +0000
reviewersmichal
bugs1402151
milestone58.0a1
Bug 1402151, part 8 - Add an argument to ParseFTPList to return the current time. r=michal If the year is omitted from a listing, then the parsing code assumes that the date occurred within the last year. To compute what the year should be, the code thus needs to know what the current year, month and day are. This patch parameterizes ParseFTPList over a function that returns a PRTime. This will allow the gtest to pass in a fixed time. Firefox itself will continue to use PR_Now to get the current time. MozReview-Commit-ID: 8IbVWbUBHYs
netwerk/streamconv/converters/ParseFTPList.cpp
netwerk/streamconv/converters/ParseFTPList.h
--- a/netwerk/streamconv/converters/ParseFTPList.cpp
+++ b/netwerk/streamconv/converters/ParseFTPList.cpp
@@ -35,17 +35,18 @@ FixupYear(PRExplodedTime* aTime)
   if (aTime->tm_year < 80) {
     aTime->tm_year += 2000;
   } else if (aTime->tm_year < 100) {
     aTime->tm_year += 1900;
   }
 }
 
 int ParseFTPList(const char *line, struct list_state *state,
-                 struct list_result *result, PRTimeParamFn timeParam)
+                 struct list_result *result, PRTimeParamFn timeParam,
+                 NowTimeFn nowTimeFn)
 {
   unsigned int carry_buf_len; /* copy of state->carry_buf_len */
   unsigned int pos;
   const char *p;
 
   if (!line || !state || !result)
     return 0;
 
@@ -1133,17 +1134,17 @@ int ParseFTPList(const char *line, struc
         {
           result->fe_time.tm_hour = pos;
           result->fe_time.tm_min  = atoi(p+3);
           if (p[5] == ':')
             result->fe_time.tm_sec = atoi(p+6);
 
           if (!state->now_time)
           {
-            state->now_time = PR_Now();
+            state->now_time = nowTimeFn();
             PR_ExplodeTime((state->now_time), timeParam, &(state->now_tm) );
           }
 
           result->fe_time.tm_year = state->now_tm.tm_year;
           if ( (( state->now_tm.tm_month << 5) + state->now_tm.tm_mday) <
                ((result->fe_time.tm_month << 5) + result->fe_time.tm_mday) )
             result->fe_time.tm_year--;
 
@@ -1611,17 +1612,17 @@ int ParseFTPList(const char *line, struc
               else
               {
                 if (p[1] == ':')
                   p--;
                 result->fe_time.tm_hour = pos;
                 result->fe_time.tm_min = atoi(p+3);
                 if (!state->now_time)
                 {
-                  state->now_time = PR_Now();
+                  state->now_time = nowTimeFn();
                   PR_ExplodeTime((state->now_time), timeParam, &(state->now_tm) );
                 }
                 result->fe_time.tm_year = state->now_tm.tm_year;
                 if ( (( state->now_tm.tm_month  << 4) + state->now_tm.tm_mday) <
                      ((result->fe_time.tm_month << 4) + result->fe_time.tm_mday) )
                   result->fe_time.tm_year--;
               } /* got year or time */
             } /* got month/mday */
--- a/netwerk/streamconv/converters/ParseFTPList.h
+++ b/netwerk/streamconv/converters/ParseFTPList.h
@@ -92,14 +92,17 @@ struct list_result
   const char *      fe_lname;     /* pointer to symlink name */
   uint32_t          fe_lnlen;     /* length of symlink name */
   char              fe_size[40];  /* size of file in bytes (<= (2^128 - 1)) */
   PRExplodedTime    fe_time;      /* last-modified time */
   int32_t           fe_cinfs;     /* file system is definitely case insensitive */
                                   /* (converting all-upcase names may be desirable) */
 };
 
+typedef PRTime (*NowTimeFn)();
+
 int ParseFTPList(const char *line,
                  struct list_state *state,
                  struct list_result *result,
-                 PRTimeParamFn timeParam = PR_LocalTimeParameters);
+                 PRTimeParamFn timeParam = PR_LocalTimeParameters,
+                 NowTimeFn nowTimeFn = PR_Now);
 
 #endif /* !ParseRTPList_h___ */