test_strptime.c revision 8b37200df5764303e2c7c2396a34a07f2a604591
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17// Minimal test program for strptime
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <time.h>
23
24int main(int argc, char **argv)
25{
26    struct tm tm;
27    char buf[255];
28
29    // For now, only test a couple of formats that use recursion
30
31    memset(&tm, 0, sizeof(tm));
32    strptime("11:14", "%R", &tm);
33    strftime(buf, sizeof(buf), "%H:%M", &tm);
34    puts(buf);
35    puts(!strcmp(buf, "11:14") ? "OK" : "FAILED");
36
37    memset(&tm, 0, sizeof(tm));
38    strptime("09:41:53", "%T", &tm);
39    strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
40    puts(buf);
41    puts(!strcmp(buf, "09:41:53") ? "OK" : "FAILED");
42
43    return EXIT_SUCCESS;
44}
45