Home | History | Annotate | Line # | Download | only in libutil
t_parsedate.c revision 1.2.6.1
      1  1.2.6.1   yamt /* $NetBSD: t_parsedate.c,v 1.2.6.1 2012/04/17 00:09:14 yamt Exp $ */
      2      1.1  njoly /*-
      3      1.1  njoly  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      4      1.1  njoly  * All rights reserved.
      5      1.1  njoly  *
      6      1.1  njoly  * Redistribution and use in source and binary forms, with or without
      7      1.1  njoly  * modification, are permitted provided that the following conditions
      8      1.1  njoly  * are met:
      9      1.1  njoly  *
     10      1.1  njoly  * 1. Redistributions of source code must retain the above copyright
     11      1.1  njoly  *    notice, this list of conditions and the following disclaimer.
     12      1.1  njoly  * 2. Redistributions in binary form must reproduce the above copyright
     13      1.1  njoly  *    notice, this list of conditions and the following disclaimer in
     14      1.1  njoly  *    the documentation and/or other materials provided with the
     15      1.1  njoly  *    distribution.
     16      1.1  njoly  *
     17      1.1  njoly  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     18      1.1  njoly  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     19      1.1  njoly  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     20      1.1  njoly  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
     21      1.1  njoly  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
     22      1.1  njoly  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23      1.1  njoly  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24      1.1  njoly  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25      1.1  njoly  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26      1.1  njoly  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
     27      1.1  njoly  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28      1.1  njoly  * SUCH DAMAGE.
     29      1.1  njoly  */
     30      1.1  njoly 
     31      1.1  njoly #include <sys/cdefs.h>
     32  1.2.6.1   yamt __RCSID("$NetBSD: t_parsedate.c,v 1.2.6.1 2012/04/17 00:09:14 yamt Exp $");
     33      1.1  njoly 
     34      1.1  njoly #include <atf-c.h>
     35      1.1  njoly #include <util.h>
     36      1.1  njoly 
     37      1.1  njoly ATF_TC(dates);
     38      1.1  njoly 
     39      1.1  njoly ATF_TC_HEAD(dates, tc)
     40      1.1  njoly {
     41  1.2.6.1   yamt 	atf_tc_set_md_var(tc, "descr", "Test unambiguous dates"
     42  1.2.6.1   yamt 	    " (PR lib/44255)");
     43      1.1  njoly }
     44      1.1  njoly 
     45      1.1  njoly ATF_TC_BODY(dates, tc)
     46      1.1  njoly {
     47      1.1  njoly 
     48      1.1  njoly 	ATF_CHECK(parsedate("69-09-10", NULL, NULL) != -1);
     49      1.1  njoly 	ATF_CHECK(parsedate("2006-11-17", NULL, NULL) != -1);
     50      1.1  njoly 	ATF_CHECK(parsedate("10/1/2000", NULL, NULL) != -1);
     51      1.1  njoly 	ATF_CHECK(parsedate("20 Jun 1994", NULL, NULL) != -1);
     52      1.1  njoly 	ATF_CHECK(parsedate("23jun2001", NULL, NULL) != -1);
     53      1.1  njoly 	ATF_CHECK(parsedate("1-sep-06", NULL, NULL) != -1);
     54      1.1  njoly 	ATF_CHECK(parsedate("1/11", NULL, NULL) != -1);
     55  1.2.6.1   yamt 	ATF_CHECK(parsedate("1500-01-02", NULL, NULL) != -1);
     56  1.2.6.1   yamt 	ATF_CHECK(parsedate("9999-12-21", NULL, NULL) != -1);
     57      1.1  njoly }
     58      1.1  njoly 
     59      1.1  njoly ATF_TC(times);
     60      1.1  njoly 
     61      1.1  njoly ATF_TC_HEAD(times, tc)
     62      1.1  njoly {
     63  1.2.6.1   yamt 	atf_tc_set_md_var(tc, "descr", "Test times"
     64  1.2.6.1   yamt 	    " (PR lib/44255)");
     65      1.1  njoly }
     66      1.1  njoly 
     67      1.1  njoly ATF_TC_BODY(times, tc)
     68      1.1  njoly {
     69      1.1  njoly 
     70      1.1  njoly 	ATF_CHECK(parsedate("10:01", NULL, NULL) != -1);
     71      1.1  njoly 	ATF_CHECK(parsedate("10:12pm", NULL, NULL) != -1);
     72      1.1  njoly 	ATF_CHECK(parsedate("12:11:01.000012", NULL, NULL) != -1);
     73      1.1  njoly 	ATF_CHECK(parsedate("12:21-0500", NULL, NULL) != -1);
     74      1.1  njoly }
     75      1.1  njoly 
     76      1.1  njoly ATF_TC(relative);
     77      1.1  njoly 
     78      1.1  njoly ATF_TC_HEAD(relative, tc)
     79      1.1  njoly {
     80  1.2.6.1   yamt 	atf_tc_set_md_var(tc, "descr", "Test relative items"
     81  1.2.6.1   yamt 	    " (PR lib/44255)");
     82      1.1  njoly }
     83      1.1  njoly 
     84      1.1  njoly ATF_TC_BODY(relative, tc)
     85      1.1  njoly {
     86      1.1  njoly 
     87      1.1  njoly 	ATF_CHECK(parsedate("-1 month", NULL, NULL) != -1);
     88      1.1  njoly 	ATF_CHECK(parsedate("last friday", NULL, NULL) != -1);
     89      1.1  njoly 	ATF_CHECK(parsedate("one week ago", NULL, NULL) != -1);
     90      1.1  njoly 	ATF_CHECK(parsedate("this thursday", NULL, NULL) != -1);
     91      1.1  njoly 	ATF_CHECK(parsedate("next sunday", NULL, NULL) != -1);
     92      1.1  njoly 	ATF_CHECK(parsedate("+2 years", NULL, NULL) != -1);
     93      1.1  njoly }
     94      1.1  njoly 
     95      1.1  njoly ATF_TP_ADD_TCS(tp)
     96      1.1  njoly {
     97      1.1  njoly 	ATF_TP_ADD_TC(tp, dates);
     98      1.1  njoly 	ATF_TP_ADD_TC(tp, times);
     99      1.1  njoly 	ATF_TP_ADD_TC(tp, relative);
    100      1.1  njoly 
    101      1.1  njoly 	return atf_no_error();
    102      1.1  njoly }
    103