Back to index

lightning-sunbird  0.9+nobinonly
regression-classify.c
Go to the documentation of this file.
00001 /* -*- Mode: C -*-
00002   ======================================================================
00003   FILE: regression-classify.c
00004   CREATOR: eric 11 February 2000
00005   
00006   $Id: regression-classify.c,v 1.3 2002/08/07 17:18:13 acampi Exp $
00007   $Locker:  $
00008     
00009  (C) COPYRIGHT 2000 Eric Busboom
00010  http://www.softwarestudio.org
00011 
00012  The contents of this file are subject to the Mozilla Public License
00013  Version 1.0 (the "License"); you may not use this file except in
00014  compliance with the License. You may obtain a copy of the License at
00015  http://www.mozilla.org/MPL/
00016  
00017  Software distributed under the License is distributed on an "AS IS"
00018  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00019  the License for the specific language governing rights and
00020  limitations under the License.
00021  
00022  The Original Code is eric. The Initial Developer of the Original
00023  Code is Eric Busboom
00024 
00025 
00026  ======================================================================*/
00027 #include <stdio.h> /* for printf */
00028 #include <errno.h>
00029 #include <string.h> /* For strerror */
00030 
00031 #include "ical.h"
00032 #include "icalss.h"
00033 #include "regression.h"
00034 
00035 extern int VERBOSE;
00036 
00037 /* Get a note about the purpose of the property*/
00038 static const char* get_note(icalcomponent *c)
00039 {
00040     icalproperty *p;
00041     const char* note = 0;
00042 
00043     if(c != 0){
00044         for(p = icalcomponent_get_first_property(c,ICAL_X_PROPERTY);
00045             p!= 0;
00046             p = icalcomponent_get_next_property(c,ICAL_X_PROPERTY)){
00047             if(strcmp(icalproperty_get_x_name(p),"X-LIC-NOTE")==0){
00048             note = icalproperty_get_x(p);
00049             }
00050         }
00051     } 
00052     
00053     if(note == 0){
00054         note = "None";
00055     }
00056     
00057     return note;
00058 }
00059 
00060 /* Get the expected result about the purpose of the property*/
00061 
00062 static const char* get_expect(icalcomponent *c)
00063 {
00064     icalproperty *p;
00065     const char* note = 0;
00066 
00067     if(c != 0){
00068         for(p = icalcomponent_get_first_property(c,ICAL_X_PROPERTY);
00069             p!= 0;
00070             p = icalcomponent_get_next_property(c,ICAL_X_PROPERTY)){
00071             if(strcmp(icalproperty_get_x_name(p),"X-LIC-EXPECT")==0){
00072             note = icalproperty_get_x(p);
00073             }
00074         }
00075     } 
00076     
00077     if(note == 0){
00078         note = "None";
00079     }
00080     
00081     return note;
00082 }
00083 
00084 void test_classify(void)
00085 {
00086     icalcomponent *c,*match; 
00087     int i=0;
00088     int error_count = 0;
00089     /* Open up the two storage files, one for the incomming components, 
00090        one for the calendar */
00091     icalset* incoming = icalset_new_file("../../test-data/incoming.ics");
00092     icalset* cal = icalset_new_file("../../test-data/calendar.ics");
00093     icalset* f = icalset_new_file("../../test-data/classify.ics");
00094 
00095     ok("opening file classify.ics", (f!=0));
00096     ok("opening file calendar.ics", (cal!=0));
00097     ok("opening file incoming.ics", (incoming!=0));
00098 
00099     /* some basic tests.. */
00100     if (f) {
00101       c = icalset_get_first_component(f);
00102       match = icalset_get_next_component(f);
00103     
00104       ok("test two vcalendars for SEQUENCE with icalclassify()",
00105         (icalclassify(c,match,"A@example.com") == ICAL_XLICCLASS_REQUESTRESCHEDULE));
00106       
00107       icalset_free(f);
00108     }
00109 
00110     assert(incoming!= 0);
00111     assert(cal!=0);
00112 
00113     /* Iterate through all of the incoming components */
00114     for(c=icalset_get_first_component(incoming);c!=0;
00115        c=icalset_get_next_component(incoming)){
00116        
00117        icalproperty_xlicclass class;
00118        icalcomponent *match = 0;
00119         const char* this_uid;
00120        const char* this_note = get_note(c);
00121        const char* expected_result = get_expect(c);
00122        const char* actual_result;
00123        const char* match_note;
00124        char msg[128];
00125 
00126        i++;
00127 
00128         /* Check this component against the restrictions imposed by
00129            iTIP. An errors will be inserted as X-LIC-ERROR properties
00130            in the component. The Parser will also insert errors if it
00131            cannot parse the component */
00132         icalcomponent_check_restrictions(c);
00133 
00134         /* If there are any errors, print out the component */
00135        
00136        error_count = icalcomponent_count_errors(c);
00137        sprintf(msg, "%s - parsing", this_note);
00138        int_is(msg, error_count, 0);
00139 
00140        if (error_count !=0) {
00141          if (VERBOSE) printf("----- Component has errors ------- \n%s-----------------\n",
00142                            icalcomponent_as_ical_string(c));
00143         }
00144 
00145         /* Use one of the icalcomponent convenience routines to get
00146            the UID. This routine will save you from having to use
00147            icalcomponent_get_inner(),
00148            icalcomponent_get_first_property(), checking the return
00149            value, and then calling icalproperty_get_uid. There are
00150            several other convenience routines for DTSTART, DTEND,
00151            DURATION, SUMMARY, METHOD, and COMMENT */
00152        this_uid = icalcomponent_get_uid(c);
00153 
00154         if(this_uid != 0){
00155             /* Look in the calendar for a component with the same UID
00156                as the incomming component. We should reall also be
00157                checking the RECURRENCE-ID. Another way to do this
00158                operation is to us icalset_find_match(), which does use
00159                the RECURRENCE-ID. */
00160             match = icalset_fetch(cal,this_uid);
00161         }
00162 
00163        
00164         /* Classify the incoming component. The third argument is the
00165            calid of the user who owns the calendar. In a real program,
00166            you would probably switch() on the class.*/
00167        class = icalclassify(c,match,"A@example.com");
00169         match_note = get_note(match);
00170        actual_result = icalproperty_enum_to_string(class);
00171        sprintf(msg, "expecting %s", expected_result);
00172        is(msg, expected_result, actual_result);
00173 
00174        if (VERBOSE) printf("Test %d\n\
00175 Incoming:      %s\n\
00176 Matched:       %s\n\
00177 Classification: %s\n\n",
00178                i,this_note,get_note(match),
00179                icalproperty_enum_to_string(class));     
00180     }
00181 
00182        icalset_free(incoming);
00183        icalset_free(cal);
00184 
00185 }
00186 
00187