/* Standalone check of format_uptime(); not part of the package build. * Build and run: tests/run.sh */ #include #include #include "../panel-plugin/uptime.h" static int failures = 0; static void check(const char *format, gulong uptime, const char *expected) { gchar *got = format_uptime(format, uptime); if (strcmp(got, expected) != 0) { printf("FAIL format=\"%s\" uptime=%lu\n expected=\"%s\"\n got =\"%s\"\n", format, uptime, expected, got); failures++; } g_free(got); } int main(void) { const gulong T = 2 * 86400 + 5 * 3600 + 7 * 60 + 9; /* 2d 5h 7m 9s */ check("%d %h %m %s", T, "2 5 7 9"); check("%H:%M:%S", T, "05:07:09"); check("%t", T, "53"); check("100%%", T, "100%"); check("%x%", T, "%x%"); /* unknown and trailing % kept */ check("line1\\nline2", T, "line1\nline2"); check("a\\\\b \\{x\\}", T, "a\\b {x}"); check("ends with \\", T, "ends with \\"); /* Cyrillic passes through byte-wise */ check("{%dд }%hч %Mм", T, "2д 5ч 07м"); check("{%dд }%hч %Mм", 5 * 3600 + 7 * 60, "5ч 07м"); /* zero days hidden */ check("{%dд\\n}%H:%M", 3600, "01:00"); check("{%dд\\n}%H:%M", T, "2д\n05:07"); check("{const}", 0, ""); /* no numbers = all zero */ check("{open %d", 0, "{open 0"); /* unclosed block literal */ check("stray}", 0, "stray}"); check("", T, ""); check(NULL, T, ""); if (failures == 0) printf("OK all checks passed\n"); return failures ? 1 : 0; }