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