{ "DatabaseDir", cfg.dbdir, 0, 512, 0 },
{ "Locale", cfg.locale, 0, 32, 0 },
{ "MonthRotate", 0, &cfg.monthrotate, 0, 0 },
+ { "MonthRotateAffectsYears", 0, &cfg.monthrotateyears, 0, 0 },
{ "DayFormat", cfg.dformat, 0, 64, 0 },
{ "MonthFormat", cfg.mformat, 0, 64, 0 },
{ "TopFormat", cfg.tformat, 0, 64, 0 },
printe(PT_Config);
}
+ if (cfg.monthrotateyears<0 || cfg.monthrotateyears>1) {
+ cfg.monthrotateyears = MONTHROTATEYEARS;
+ snprintf(errorstring, 1024, "%s MonthRotateAffectsYears, %s \"%d\".", invalidvalue, resettingto, cfg.monthrotateyears);
+ printe(PT_Config);
+ }
+
if (cfg.maxbw<0 || cfg.maxbw>BWMAX) {
cfg.maxbw = DEFMAXBW;
snprintf(errorstring, 1024, "%s MaxBandwidth, %s \"%d\".", invalidvalue, resettingto, cfg.maxbw);
cfg.qmode = DEFQMODE;
cfg.sampletime = DEFSAMPTIME;
cfg.monthrotate = MONTHROTATE;
+ cfg.monthrotateyears = MONTHROTATEYEARS;
cfg.unitmode = UNITMODE;
cfg.rateunitmode = RATEUNITMODE;
cfg.ostyle = OSTYLE;
/* on which day should months change */
#define MONTHROTATE 1
+#define MONTHROTATEYEARS 0
/* date output formats for -d, -m, -t and image header*/
/* see 'man date' for control codes 1.x values <1.8 values */
char cbg[8], cedge[8], cheader[8], cheadertitle[8], cheaderdate[8], ctext[8];
char cline[8], clinel[8], cvnstat[8], crx[8], crxd[8], ctx[8], ctxd[8];
int32_t unitmode, rateunitmode, rateunit, bvar, qmode, sampletime, hourlyrate, summaryrate;
- int32_t monthrotate, maxbw, spacecheck, traflessday, transbg, ostyle;
+ int32_t monthrotate, monthrotateyears, maxbw, spacecheck, traflessday, transbg, ostyle;
int32_t defaultdecimals, hourlydecimals, hourlystyle;
char cfgfile[512], logfile[512], pidfile[512];
char daemonuser[33], daemongroup[33];
}
END_TEST
+START_TEST(db_get_date_generator_can_generate_dates)
+{
+ defaultcfg();
+
+ ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL);
+
+ ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL);
+}
+END_TEST
+
+START_TEST(db_get_date_generator_can_generate_dates_with_monthrotate)
+{
+ defaultcfg();
+
+ cfg.monthrotate = 10;
+ cfg.monthrotateyears = 0;
+
+ ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', datetime(foo, '-9 days'), 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL);
+
+ ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL);
+
+ cfg.monthrotate = 8;
+ cfg.monthrotateyears = 1;
+
+ ck_assert_ptr_ne(strstr(db_get_date_generator(0, 0, "foo"), "minutes"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(1, 0, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(2, 0, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(5, 0, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(3, 0, "foo"), "strftime('%Y-%m-01', datetime(foo, '-7 days'), 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(4, 0, "foo"), "strftime('%Y-01-01', datetime(foo, '-7 days'), 'localtime')"), NULL);
+
+ ck_assert_ptr_ne(strstr(db_get_date_generator(0, 1, "foo"), "minutes"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(1, 1, "foo"), "strftime('%Y-%m-%d %H:00:00', foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(2, 1, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(5, 1, "foo"), "date(foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(3, 1, "foo"), "strftime('%Y-%m-01', foo, 'localtime')"), NULL);
+ ck_assert_ptr_ne(strstr(db_get_date_generator(4, 1, "foo"), "strftime('%Y-01-01', foo, 'localtime')"), NULL);
+}
+END_TEST
+
void add_dbsql_tests(Suite *s)
{
TCase *tc_dbsql = tcase_create("DB SQL");
tcase_add_test(tc_dbsql, db_getdata_range_can_get_hours_with_range_on_same_hour);
tcase_add_test(tc_dbsql, db_addtraffic_without_monthrotate);
tcase_add_test(tc_dbsql, db_addtraffic_with_monthrotate);
+ tcase_add_test(tc_dbsql, db_get_date_generator_can_generate_dates);
+ tcase_add_test(tc_dbsql, db_get_date_generator_can_generate_dates_with_monthrotate);
suite_add_tcase(s, tc_dbsql);
}