///////////////////////////////////////////////////////////////////////////// // Copyright (C) 2010 The Linux Foundation. All rights reserved. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // This file contains tests for the following library: // libgobject-2.0, // section: "GVALUE_ARRAYS". // // This C file was generated by the T2C system developed in ISPRAS // for The Linux Foundation. ///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// // To build a standalone version of the tests, i.e. the one that does not // depend on TETware Lite test harness, please follow the instructions below. // (A standalone executable like this can prove useful for debugging.) // // 1. Make sure the T2C_ROOT and T2C_SUITE_ROOT environment variables are set properly. // T2C_ROOT should contain a path to the main directory of T2C Framework. // For example, the executable of the T2C C code generator is $T2C_ROOT/t2c/bin/t2c. // T2C_SUITE_ROOT is main test suite directory, the one where the tet execution // configuration file (tetexec.cfg) resides as well as tet_code file etc. // // 2. If the standalone version of the tests is to be built with lsbcc or lsbc++, // make sure that lsbcc (or lsbc++, respectively) is somewhere in your PATH. // You should also add a path to the LSB pkg-config data // (usually /opt/lsb/lib/pkgconfig or /opt/lsb/lib64/pkgconfig) to the beginning of // the string contained in PKG_CONFIG_PATH environment variable. // // 3. Before building the standalone version of a test, check if the following // files and directories exist: // $T2C_SUITE_ROOT/gobject-t2c/tests // $T2C_SUITE_ROOT/gobject-t2c/tests/common.mk // $T2C_SUITE_ROOT/gobject-t2c/tests/gobject_value_arrays/ // $T2C_SUITE_ROOT/gobject-t2c/tests/gobject_value_arrays/gobject_value_arrays.c // $T2C_SUITE_ROOT/gobject-t2c/tests/gobject_value_arrays/Makefile // // If some of these are missing, just run ./gen_code.sh script from the $T2C_SUITE_ROOT // directory. After that all necessary files and directories should exist. // // 4. Execute the following commands: // cd $T2C_SUITE_ROOT/gobject-t2c/tests/gobject_value_arrays/ // make clean // make debug // // The C-code of the tests is the same both for release and debug (standalone) // versions. // main() function for standalone execution is defined in // "$T2C_ROOT/t2c/debug/src/dbg_main.c" along with some utility stuff. // The TET API stubs are declared in "$T2C_ROOT/t2c/debug/include/tet_api.h" // // Note that all the test purposes of a standalone test are executed // in the same process to simplify debugging (some debuggers may not // handle fork() calls properly by default). // // WAIT_TIME configuration parameter has no effect on the standalone tests. // They will not be interrupted, no matter how long they run. Otherwise they // could be stopped in the middle of the debugging process (because their time // had expired) which is probably not what you want. ///////////////////////////////////////////////////////////////////////////// #include #include #include #include #include const char* test_name_ = "gobject_value_arrays"; const char* suite_subdir_ = "gobject-t2c"; // List of requirement catalogs to be loaded const char* rcat_names_[] = { "gobject_value_arrays", NULL }; const char* rel_href_path_ = "gobject-t2c/tests/gobject_value_arrays/gobject_value_arrays.html#%s%d\">"; char* t2c_href_tpl_ = NULL; char* t2c_href_full_tpl_ = NULL; // Name of the env. variable that is used to determine whether the REQ // implementation should output just IDs (value = 0, default) or hyperlinks // to the html representation, enclosed in some pseudotags for DTK Manager // (value != 0). const char* t2c_gen_hlinks_name = "T2C_GEN_HLINKS"; int gen_hlinks = 0; char* init_fail_reason_ = NULL; /* g_value_array_append DONE g_value_array_copy DONE g_value_array_free DONE g_value_array_get_nth DONE g_value_array_insert DONE g_value_array_new DONE g_value_array_prepend DONE g_value_array_remove DONE g_value_array_sort DONE g_value_array_sort_with_data DONE */ //Global variables, used in get_value function //They must be declared as global , because get_value can return pointers to these variables. gint gintVar; guint guintVar; gint64 gint64Var; guint64 huint64Var; gchar gcharVar; guchar gucharVar; glong glongVar; gulong gulongVar; guchar gucharVar; gfloat gfloatVar; gdouble gdoubleVar; gboolean gbooleanVar; char* message; // set_value function generates this message , and it contains the unique text for each GType char* sortMessage; //this message will be generated in cmp or cmp_data interfaces GType sortType; // //This function gets the GType and calls the correct set interface for this type //For example, it calls g_value_set_int for G_TYPE_INT. // void set_value(GType initType,GValue* value, void* vl ) { if(initType==G_TYPE_INT) { g_value_set_int(value,*((gint *)vl)); message="The function should return %d,but returns %d"; return; } else if(initType==G_TYPE_CHAR) { g_value_set_char(value,*((gchar *)vl)); message="The function should return %c,but returns %c"; return; } else if(initType==G_TYPE_UCHAR) { g_value_set_uchar(value,*((guchar *)vl)); message="The function should return %u,but returns %u"; return; } else if(initType==G_TYPE_LONG) { g_value_set_long(value,*((glong *)vl)); message="The function should return %ld,but returns %ld"; return; } else if(initType==G_TYPE_ULONG) { g_value_set_ulong(value,*((gulong *)vl)); return; } else if(initType==G_TYPE_INT64) { g_value_set_int64(value,*((gint64 *)vl)); return; } else if(initType==G_TYPE_UINT) { g_value_set_uint(value,*((guint *)vl)); message="The function should return %u,but returns %u"; return; } else if(initType==G_TYPE_BOOLEAN) { g_value_set_boolean(value,*((gboolean *)vl)); return; } else if(initType==G_TYPE_DOUBLE) { g_value_set_double(value,*((gdouble *)vl)); message="The function should return %f,but returns %f"; return; } else if(initType==G_TYPE_FLOAT) { g_value_set_float(value,*((gfloat *)vl)); message="The function should return %f,but returns %f"; return; } return ; } void* get_value(GType initType,GValue* value ) { if(initType==G_TYPE_INT) { gintVar=g_value_get_int(value); return (void*)(&gintVar); } else if(initType==G_TYPE_CHAR) { gcharVar=g_value_get_char(value); return (void*)(&gcharVar); } else if(initType==G_TYPE_UCHAR) { gucharVar=g_value_get_uchar(value); return (void*)(&gucharVar); } else if(initType==G_TYPE_LONG) { glongVar=g_value_get_long(value); return (void*)(&glongVar); } else if(initType==G_TYPE_ULONG) { gulongVar=g_value_get_ulong(value); return (void*)(&gulongVar); } else if(initType==G_TYPE_INT64) { gint64Var=g_value_get_int64(value); return (void*)(&gint64Var); } else if(initType==G_TYPE_UINT) { guintVar=g_value_get_uint(value); return (void*)(&gintVar); } else if(initType==G_TYPE_BOOLEAN) { gbooleanVar=g_value_get_boolean(value); return (void*)(&gbooleanVar); } else if(initType==G_TYPE_DOUBLE) { gdoubleVar=g_value_get_double(value); return (void*)(&gdoubleVar); } else if(initType==G_TYPE_FLOAT) { gfloatVar=g_value_get_float(value); return (void*)(&gfloatVar); } return (void *)NULL; } ///////////////////////////////////////////////////////////////////////// //compare function for g_value_array_sort gint cmp (gconstpointer a, gconstpointer b) { if(sortType==G_TYPE_INT) { GValue* aValue=(GValue*)a; gint a1=g_value_get_int(aValue); GValue* bValue=(GValue*)b; gint b1=g_value_get_int(bValue); sortMessage="After sorting array, the %d-th element of array should be %d, but is %d"; if (a1 - b1 < 0) return -1; if (a1 - b1 > 0) return 1; return 0; } if(sortType==G_TYPE_CHAR) { GValue* aValue=(GValue*)a; gchar a1=g_value_get_char(aValue); GValue* bValue=(GValue*)b; gchar b1=g_value_get_char(bValue); sortMessage="After sorting array, the %d-th element of array should be %c, but is %c"; if (a1 - b1 < 0) return -1; if (a1 - b1 > 0) return 1; return 0; } if(sortType==G_TYPE_UCHAR) { GValue* aValue=(GValue*)a; guchar a1=g_value_get_uchar(aValue); GValue* bValue=(GValue*)b; guchar b1=g_value_get_uchar(bValue); sortMessage="After sorting array, the %d-th element of array should be %u, but is %u"; if (a1 - b1 < 0) return -1; if (a1 - b1 > 0) return 1; return 0; } if(sortType==G_TYPE_DOUBLE) { GValue* aValue=(GValue*)a; gdouble a1=g_value_get_double(aValue); GValue* bValue=(GValue*)b; gdouble b1=g_value_get_double(bValue); sortMessage="After sorting array, the %d-th element of array should be %f, but is %f"; if (a1 - b1 < 0) return -1; if (a1 - b1 > 0) return 1; return 0; } return -1; } gint cmp_data (gconstpointer a, gconstpointer b,gpointer userData) { if(sortType==G_TYPE_INT) { GValue* aValue=(GValue*)a; gint a1=g_value_get_int(aValue); GValue* bValue=(GValue*)b; gint b1=g_value_get_int(bValue); GValue* userValue=(GValue*)userData; gint user=g_value_get_int(userValue); sortMessage="After sorting array, the %d-th element of array should be %d, but is %d"; if (a1 - b1 < user) return -1; if (a1 - b1 > user) return 1; return 0; } if(sortType==G_TYPE_CHAR) { GValue* aValue=(GValue*)a; gchar a1=g_value_get_char(aValue); GValue* bValue=(GValue*)b; gchar b1=g_value_get_char(bValue); GValue* userValue=(GValue*)userData; gchar user=g_value_get_char(userValue); sortMessage="After sorting array, the %d-th element of array should be %c, but is %c"; if (a1 - b1 < user) return -1; if (a1 - b1 > user) return 1; return 0; } if(sortType==G_TYPE_UCHAR) { GValue* aValue=(GValue*)a; guchar a1=g_value_get_uchar(aValue); GValue* bValue=(GValue*)b; guchar b1=g_value_get_uchar(bValue); GValue* userValue=(GValue*)userData; guchar user=g_value_get_uchar(userValue); sortMessage="After sorting array, the %d-th element of array should be %u, but is %u"; if (a1 - b1 < user) return -1; if (a1 - b1 > user) return 1; return 0; } if(sortType==G_TYPE_DOUBLE) { GValue* aValue=(GValue*)a; gdouble a1=g_value_get_double(aValue); GValue* bValue=(GValue*)b; gdouble b1=g_value_get_double(bValue); GValue* userValue=(GValue*)userData; gdouble user=g_value_get_double(userValue); sortMessage="After sorting array, the %d-th element of array should be %f, but is %f"; if (a1 - b1 < user) return -1; if (a1 - b1 > user) return 1; return 0; } return -1; } void main () { #define COUNT 6 #define TYPE G_TYPE_INT #define BUILT_IN_TYPE gint #define DATA_ARRAY {2,1,5,4,3,6} #define RESULT_ARRAY {1,2,3,4,5,6} #define USER_DATA 1 int i; gboolean check=TRUE; gboolean check_count=TRUE; sortType=TYPE; GValueArray* array=NULL; g_type_init(); array=g_value_array_new (COUNT); BUILT_IN_TYPE data_array []=DATA_ARRAY; BUILT_IN_TYPE result_array[]=RESULT_ARRAY; GValue a_value[COUNT]={{0,}}; BUILT_IN_TYPE user=USER_DATA; GValue userValue={0}; g_value_init (&userValue, TYPE); set_value(TYPE,&userValue,(void*)(&user)); for(i=0;in_values!=COUNT) { printf("Before sorting the array should contain %d values, but contains %d",COUNT,array->n_values); } g_value_array_sort_with_data(array,cmp_data,(void*)&userValue); if(array->n_values!=COUNT) { printf("After sorting the array should contain %d values, but contains %d",COUNT,array->n_values); } /* * number of values contained in the array */ for(i=0;i