Natools

Check-in [ba34be19be]
Login
Overview
Comment:time_io-tests: add test for leap second workaround on implementations that don't support them
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ba34be19bea6afa65e53608d95206b65a8d5c730
User & Date: nat on 2014-08-21 20:52:27
Other Links: manifest | tags
Context
2014-08-22
17:05
time_io-tests: add a check with an invalid leap-second time, to reach full coverage check-in: c517c2f45f user: nat tags: trunk
2014-08-21
20:52
time_io-tests: add test for leap second workaround on implementations that don't support them check-in: ba34be19be user: nat tags: trunk
2014-08-20
19:49
time_io-rfc_3339: add extra arguments to work around implementations without leap second support check-in: 21534f262f user: nat tags: trunk
Changes

Modified tests/natools-time_io-tests.adb from [2310ce4bce] to [c77496cbaa].

227
228
229
230
231
232
233
234




235
236





237

238
239






240
241
242
243
244
245
246
227
228
229
230
231
232
233

234
235
236
237
238

239
240
241
242
243
244
245
246

247
248
249
250
251
252
253
254
255
256
257
258
259







-
+
+
+
+

-
+
+
+
+
+

+

-
+
+
+
+
+
+









   procedure Read_From_RFC_3339 (Report : in out NT.Reporter'Class) is
      Test : NT.Test := Report.Item ("RFC-3339 -> Ada.Calendar.Time");
      Now : constant Extended_Time
        := (Ada.Calendar.Clock, Ada.Calendar.Time_Zones.UTC_Time_Offset);

      function Value (Img : String) return Extended_Time;
      function Value
        (Img : String;
         Expected_Leap : Boolean := False)
        return Extended_Time;

      function Value (Img : String) return Extended_Time is
      function Value
        (Img : String;
         Expected_Leap : Boolean := False)
        return Extended_Time
      is
         Result : Extended_Time;
         Leap : Boolean;
      begin
         RFC_3339.Value (Img, Result.Time, Result.Offset);
         RFC_3339.Value (Img, Result.Time, Result.Offset, Leap);
         if Leap /= Expected_Leap then
            Test.Fail ("Unexpected leap second flag at "
              & Boolean'Image (Leap)
              & " for """ & Img & '"');
         end if;
         return Result;
      end Value;
   begin
      Check (Test,
         (Ada.Calendar.Formatting.Time_Of
           (1985, 04, 12, 23, 20, 50, 0.52, False, 0), 0),
         Value ("1985-04-12T23:20:50.52Z"),
260
261
262
263
264
265
266












267
268
269
270
271
272
273
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298







+
+
+
+
+
+
+
+
+
+
+
+







            "[3] UTC leap second:");

         Check (Test,
            (Ada.Calendar.Formatting.Time_Of
              (1990, 12, 31, 15, 59, 59, 0.0, True, -8 * 60), -8 * 60),
            Value ("1990-12-31T15:59:60-08:00"),
            "[4] Leap second with time offset:");
      else
         Check (Test,
            (Ada.Calendar.Formatting.Time_Of
              (1990, 12, 31, 23, 59, 59, 0.0, False, 0), 0),
            Value ("1990-12-31T23:59:60Z", True),
            "[3] UTC leap second:");

         Check (Test,
            (Ada.Calendar.Formatting.Time_Of
              (1990, 12, 31, 15, 59, 59, 0.0, False, -8 * 60), -8 * 60),
            Value ("1990-12-31T15:59:60-08:00", True),
            "[4] Leap second with time offset:");
      end if;

      Check (Test,
         (Ada.Calendar.Formatting.Time_Of
           (1937, 01, 01, 12, 0, 27, 0.87, False, 20), 20),
         Value ("1937-01-01T12:00:27.87+00:20"),
         "[5] Noon in the Netherlands:");
313
314
315
316
317
318
319
















320
321
322
323
324
325
326
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







            RFC_3339.Image
              (Ada.Calendar.Formatting.Time_Of
                 (1990, 12, 31, 15, 59, 59, 0.0, True, -8 * 60),
               -8 * 60, 0),
            "[4] Leap second with time offset:");
      end if;

      Check (Test,
         "1990-12-31T23:59:60Z",
         RFC_3339.Image
           (Ada.Calendar.Formatting.Time_Of
              (1990, 12, 31, 23, 59, 59, 0.0, False, 0),
            0, 0, True),
         "[3b] UTC leap second with workaround:");

      Check (Test,
         "1990-12-31T15:59:60-08:00",
         RFC_3339.Image
           (Ada.Calendar.Formatting.Time_Of
              (1990, 12, 31, 15, 59, 59, 0.0, False, -8 * 60),
            -8 * 60, 0, True),
         "[4b] Leap second with time offset and workaround:");

      Check (Test,
         "1937-01-01T12:00:27.87+00:20",
         RFC_3339.Image
           (Ada.Calendar.Formatting.Time_Of
              (1937, 01, 01, 12, 0, 27, 0.87, False, 20),
            20, 2),
         "[5] Noon in the Netherlands:");