test_strptime.c revision 8b37200df5764303e2c7c2396a34a07f2a604591
18b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten/*
28b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten * Copyright (C) 2011 The Android Open Source Project
38b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten *
48b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten * Licensed under the Apache License, Version 2.0 (the "License");
58b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten * you may not use this file except in compliance with the License.
68b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten * You may obtain a copy of the License at
78b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten *
88b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten *      http://www.apache.org/licenses/LICENSE-2.0
98b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten *
108b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten * Unless required by applicable law or agreed to in writing, software
118b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten * distributed under the License is distributed on an "AS IS" BASIS,
128b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten * See the License for the specific language governing permissions and
148b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten * limitations under the License.
158b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten */
168b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten
178b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten// Minimal test program for strptime
188b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten
198b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten#include <stdio.h>
208b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten#include <stdlib.h>
218b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten#include <string.h>
228b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten#include <time.h>
238b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten
248b37200df5764303e2c7c2396a34a07f2a604591Glenn Kastenint main(int argc, char **argv)
258b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten{
268b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    struct tm tm;
278b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    char buf[255];
288b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten
298b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    // For now, only test a couple of formats that use recursion
308b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten
318b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    memset(&tm, 0, sizeof(tm));
328b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    strptime("11:14", "%R", &tm);
338b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    strftime(buf, sizeof(buf), "%H:%M", &tm);
348b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    puts(buf);
358b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    puts(!strcmp(buf, "11:14") ? "OK" : "FAILED");
368b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten
378b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    memset(&tm, 0, sizeof(tm));
388b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    strptime("09:41:53", "%T", &tm);
398b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
408b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    puts(buf);
418b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    puts(!strcmp(buf, "09:41:53") ? "OK" : "FAILED");
428b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten
438b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten    return EXIT_SUCCESS;
448b37200df5764303e2c7c2396a34a07f2a604591Glenn Kasten}
45