~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to unittests/time_test.cc

tests for to_decimal methods
parameterized tests for more formats possible for from_strings, however they don't compile ATM so I commented them out

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "config.h"
22
22
 
23
23
#include <gtest/gtest.h>
 
24
#include <drizzled/decimal.h>
24
25
#include <drizzled/temporal.h>
25
26
#include <drizzled/temporal_format.h>
26
27
 
33
34
protected:
34
35
  Time sample_time;
35
36
  bool result;
 
37
  uint32_t hours, minutes, seconds;
36
38
  
37
39
  Time identical_with_sample_time, before_sample_time, after_sample_time;
38
40
  
45
47
    Generator::TimeGen::make_time(&after_sample_time, 18, 35, 0);
46
48
    
47
49
  }
 
50
 
 
51
  void assign_time_values()
 
52
  {
 
53
    hours= sample_time.hours();
 
54
    minutes= sample_time.minutes();
 
55
    seconds= sample_time.seconds();
 
56
  }
 
57
 
 
58
  void from_string(const char *string)
 
59
  {
 
60
    
 
61
    init_temporal_formats();
 
62
    result= sample_time.from_string(string, strlen(string));
 
63
    deinit_temporal_formats();
 
64
    
 
65
    assign_time_values();
 
66
  }
48
67
};
49
68
 
50
69
TEST_F(TimeTest, operatorEqual_ComparingWithIdencticalTime_ShouldReturn_True)
228
247
  ASSERT_EQ(Time::MAX_STRING_LENGTH - 1, length);  
229
248
}
230
249
 
231
 
TEST_F(TimeTest, from_string_validString_shouldPopulateCorrectly)
232
 
{
233
 
  char valid_string[Time::MAX_STRING_LENGTH]= "18:34:59";
234
 
  uint32_t hours, minutes, seconds;
235
 
 
236
 
  init_temporal_formats();
237
 
  
238
 
  result= sample_time.from_string(valid_string, Time::MAX_STRING_LENGTH - 1);
239
 
  ASSERT_TRUE(result);
240
 
  
241
 
  hours= sample_time.hours();
242
 
  minutes= sample_time.minutes();
243
 
  seconds= sample_time.seconds();
244
 
 
245
 
  deinit_temporal_formats();
246
 
  
247
 
  EXPECT_EQ(18, hours);
248
 
  EXPECT_EQ(34, minutes);
249
 
  EXPECT_EQ(59, seconds);
250
 
}
251
 
 
252
 
TEST_F(TimeTest, from_string_invalidString_shouldReturn_False)
253
 
{
254
 
  char invalid_string[Time::MAX_STRING_LENGTH]= "1o:34:59";
255
 
 
256
 
  init_temporal_formats();
257
 
  result= sample_time.from_string(invalid_string, Time::MAX_STRING_LENGTH - 1);
258
 
  deinit_temporal_formats();
259
 
  
260
 
  ASSERT_FALSE(result);
261
 
}
262
 
 
263
250
TEST_F(TimeTest, to_int32_t)
264
251
{
265
252
  int32_t representation;
271
258
 
272
259
TEST_F(TimeTest, from_int32_t_shouldPopulateTimeCorrectly)
273
260
{
274
 
  uint32_t decoded_hours, decoded_minutes, decoded_seconds;
275
 
 
276
261
  sample_time.from_int32_t(183459);
277
262
  
278
 
  decoded_hours= sample_time.hours();
279
 
  decoded_minutes= sample_time.minutes();
280
 
  decoded_seconds= sample_time.seconds();
 
263
  assign_time_values();;
281
264
  
282
 
  EXPECT_EQ(18, decoded_hours);
283
 
  EXPECT_EQ(34, decoded_minutes);
284
 
  EXPECT_EQ(59, decoded_seconds);
 
265
  EXPECT_EQ(18, hours);
 
266
  EXPECT_EQ(34, minutes);
 
267
  EXPECT_EQ(59, seconds);
285
268
}
286
269
 
287
270
TEST_F(TimeTest, from_time_t)
288
271
{
289
 
  uint32_t hours, minutes, seconds;
290
 
  
291
272
  sample_time.from_time_t(59588);
292
273
  
293
 
  hours= sample_time.hours();
294
 
  minutes= sample_time.minutes();
295
 
  seconds= sample_time.seconds();
 
274
  assign_time_values();
296
275
  
297
276
  EXPECT_EQ(16, hours);  
298
277
  EXPECT_EQ(33, minutes);
299
278
  EXPECT_EQ(8, seconds);
300
279
}
 
280
 
 
281
TEST_F(TimeTest, to_decimal)
 
282
{
 
283
  drizzled::my_decimal to;
 
284
  Generator::TimeGen::make_time(&sample_time, 8, 4, 9);
 
285
 
 
286
  sample_time.to_decimal(&to);
 
287
  
 
288
  ASSERT_EQ(80409, to.buf[0]);
 
289
}
 
290
 
 
291
TEST_F(TimeTest, from_string_invalidString_shouldReturn_False)
 
292
{
 
293
  char invalid_string[Time::MAX_STRING_LENGTH]= "1o:34:59";
 
294
  
 
295
  init_temporal_formats();
 
296
  result= sample_time.from_string(invalid_string, strlen(invalid_string));
 
297
  deinit_temporal_formats();
 
298
  
 
299
  ASSERT_FALSE(result);
 
300
}
 
301
 
 
302
TEST_F(TimeTest, from_string_validString_minuteAndSecond_shouldPopulateCorrectly)
 
303
{
 
304
  char valid_string[Time::MAX_STRING_LENGTH]= "4:52";
 
305
 
 
306
  from_string(valid_string);
 
307
 
 
308
  EXPECT_EQ(4, minutes);
 
309
  EXPECT_EQ(52, seconds);
 
310
}
 
311
 
 
312
TEST_F(TimeTest, from_string_validString_minuteAndSecondNoColon_shouldPopulateCorrectly)
 
313
{
 
314
  char valid_string[Time::MAX_STRING_LENGTH]= "3456";
 
315
  
 
316
  from_string(valid_string);
 
317
  
 
318
  EXPECT_EQ(34, minutes);
 
319
  EXPECT_EQ(56, seconds);
 
320
}
 
321
 
 
322
TEST_F(TimeTest, from_string_validString_secondsOnly_shouldPopulateCorrectly)
 
323
{
 
324
  char valid_string[Time::MAX_STRING_LENGTH]= "59";
 
325
  
 
326
  from_string(valid_string);
 
327
  
 
328
  EXPECT_EQ(59, seconds);
 
329
}
 
330
/*
 
331
class TimeFromStringTest: public ::testing::TestWithParam<const char*>
 
332
{
 
333
  protected:
 
334
    Time time;
 
335
    bool result;
 
336
    uint32_t hours, minutes, seconds;
 
337
    
 
338
    virtual void SetUp()
 
339
    {
 
340
      init_temporal_formats();
 
341
    }
 
342
    
 
343
    virtual void TearDown()
 
344
    {
 
345
      deinit_temporal_formats();
 
346
    }
 
347
    
 
348
    void assign_time_values()
 
349
    {
 
350
      hours= time.hours();
 
351
      minutes= time.minutes();
 
352
      seconds= time.seconds();
 
353
    }
 
354
};
 
355
 
 
356
TEST_P(TimeFromStringTest, from_string_validString_formatsWithAllTimeComponentsPresent_shouldPopulateCorrectly)
 
357
{
 
358
  const char *valid_string = GetParam();
 
359
 
 
360
  result= time.from_string(valid_string, strlen(valid_string));
 
361
  ASSERT_TRUE(result);
 
362
  
 
363
  assign_time_values();
 
364
 
 
365
  EXPECT_EQ(8, hours);
 
366
  EXPECT_EQ(4, minutes);
 
367
  EXPECT_EQ(9, seconds);
 
368
}
 
369
 
 
370
INSTANTIATE_TEST_CASE_P(FormatsWithAllTimeComponentsPresent, TimeFromStringTest,
 
371
                        ::testing::Values("080409",
 
372
                                          "80409",
 
373
                                          "08:04:09",
 
374
                                          "8:04:09",
 
375
                                          "8:04:9",
 
376
                                          "8:4:9"));
 
377
*/                                          
 
 
b'\\ No newline at end of file'