📄 test-field.c
字号:
/* librecord2 - Record Object manipulation and storage library 2 * * Authors: YE Nan <nan.ye@orange-ftgroup.com> * * This software and associated documentation files (the "Software") * are copyright (C) 2005 LiPS Linux Phone Standards Forum [FranceTelecom] * All Rights Reserved. * * A copyright license is hereby granted for redistribution and use of * the Software in source and binary forms, with or without modification, * provided that the following conditions are met: * - Redistributions of source code must retain the above copyright notice, * this copyright license and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this copyright license and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - Neither the name of LiPS nor the names of its Members may be used * to endorse or promote products derived from the Software without * specific prior written permission. * * A patent license for any Necessary Claims owned by Members of LiPS Forum * to make, have made, use, import, offer to sell, lease and sell or otherwise * distribute any implementation compliant with the any specification adopted * by the LiPS Forumcan be obtained from the respective Members on reasonable * and non-discriminatory terms and conditions and under reciprocity, as * regulated in more detail in the Internal Policy of the LiPS Forum. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER, ITS MEMBERS AND CONTRIBUTORS * "AS IS", AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * AND NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER, * ITS MEMBERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */#include <stdio.h>#include <stdlib.h>#include <time.h>#include <glib.h>#include <field.h>static voidgen_field_boolean(){ FieldDescriptor * fdesc = NULL; Field * field = NULL; gboolean b = FALSE; g_print("%s(): entring\n", __FUNCTION__); fdesc = field_descriptor_new(0, FIELD_TYPE_BOOLEAN, FIELD_ATTR_NONE, sizeof(gboolean)); field = field_new(fdesc); field_set_value(field, &b, FIELD_SIZE_AUTO); field_print(field); field_free(field); field_descriptor_free(fdesc); return;}static voidgen_field_integer(){ FieldDescriptor * fdesc = NULL; Field * field = NULL; gint i = 65535; g_print("%s(): entring\n", __FUNCTION__); fdesc = field_descriptor_new(0, FIELD_TYPE_INTEGER, FIELD_ATTR_NONE, sizeof(gint)); field = field_new(fdesc); field_set_value(field, &i, FIELD_SIZE_AUTO); field_print(field); field_free(field); field_descriptor_free(fdesc); return;}static voidgen_field_float(){ FieldDescriptor * fdesc = NULL; Field * field = NULL; gfloat f = 3.1415926; g_print("%s(): entring\n", __FUNCTION__); fdesc = field_descriptor_new(0, FIELD_TYPE_FLOAT, FIELD_ATTR_NONE, sizeof(gfloat)); field = field_new(fdesc); field_set_value(field, &f, FIELD_SIZE_AUTO); field_print(field); field_free(field); field_descriptor_free(fdesc); return;}static voidgen_field_string(){ FieldDescriptor * fdesc = NULL; Field * field = NULL; gchar * str = "ABC测试字符串"; g_print("%s(): entring\n", __FUNCTION__); fdesc = field_descriptor_new(0, FIELD_TYPE_STRING, FIELD_ATTR_NONE, 5); field = field_new(fdesc); field_set_value(field, str, FIELD_SIZE_AUTO); field_print(field); field_free(field); field_descriptor_free(fdesc); return;}static voidgen_field_date(){ FieldDescriptor * fdesc = NULL; Field * field = NULL; time_t t; t = time(NULL); g_print("%s(): entring\n", __FUNCTION__); fdesc = field_descriptor_new(0, FIELD_TYPE_DATE, FIELD_ATTR_NONE, sizeof(time_t)); field = field_new(fdesc); field_set_value(field, &t, sizeof(time_t)); field_print(field); field_free(field); field_descriptor_free(fdesc); return;}static voidgen_field_binary(){ FieldDescriptor * fdesc = NULL; Field * field = NULL; guint8 bytes[] = { 0x01, 0x05, 0x08, 0x0A, 0x0B, 0x02, 0x06, 0x09, 0x0E, 0x0C, 0x03, 0x07, 0x00, 0x0F, 0x0D, 0x04, }; g_print("%s(): entring\n", __FUNCTION__); fdesc = field_descriptor_new(0, FIELD_TYPE_BINARY, FIELD_ATTR_NONE, 40); field = field_new(fdesc); field_set_value(field, &bytes, sizeof(bytes)); field_print(field); field_free(field); field_descriptor_free(fdesc); return;}int main (int argc, char *argv[]){ gen_field_boolean(); gen_field_integer(); gen_field_float(); gen_field_date(); gen_field_string(); gen_field_binary(); return EXIT_SUCCESS;}/*vi:ts=2:nowrap:ai:expandtab */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -