19dedec0cSmrg/* 29dedec0cSmrg * Copyright (c) 2022, Oracle and/or its affiliates. 39dedec0cSmrg * 49dedec0cSmrg * Permission is hereby granted, free of charge, to any person obtaining a 59dedec0cSmrg * copy of this software and associated documentation files (the "Software"), 69dedec0cSmrg * to deal in the Software without restriction, including without limitation 79dedec0cSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 89dedec0cSmrg * and/or sell copies of the Software, and to permit persons to whom the 99dedec0cSmrg * Software is furnished to do so, subject to the following conditions: 109dedec0cSmrg * 119dedec0cSmrg * The above copyright notice and this permission notice (including the next 129dedec0cSmrg * paragraph) shall be included in all copies or substantial portions of the 139dedec0cSmrg * Software. 149dedec0cSmrg * 159dedec0cSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 169dedec0cSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 179dedec0cSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 189dedec0cSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 199dedec0cSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 209dedec0cSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 219dedec0cSmrg * DEALINGS IN THE SOFTWARE. 229dedec0cSmrg */ 239dedec0cSmrg 249dedec0cSmrg/* Test code for ProtocolStream Get/Put functions in src/EditResCom.c */ 259dedec0cSmrg#include <X11/Xmu/EditresP.h> 269dedec0cSmrg#include <assert.h> 279dedec0cSmrg 289dedec0cSmrgstatic const char *test_string = "\tIt was a dark and stormy night...\n"; 299dedec0cSmrg 309dedec0cSmrg#define FillBuffer(d, v) memset(d, v, sizeof(d)) 319dedec0cSmrg 329dedec0cSmrgint main(void) 339dedec0cSmrg{ 349dedec0cSmrg ProtocolStream ps = { 0, 0, NULL, NULL, NULL }; 359dedec0cSmrg unsigned char c; 369dedec0cSmrg unsigned short s; 379dedec0cSmrg unsigned long l; 389dedec0cSmrg Bool res; 399dedec0cSmrg char *str; 409dedec0cSmrg unsigned long ids[] = { 1, 10, 0xbabe, 0xbabeface, 0xffffffff }; 419dedec0cSmrg WidgetInfo i = { 429dedec0cSmrg .num_widgets = sizeof(ids) / sizeof(ids[0]), 439dedec0cSmrg .ids = ids, 449dedec0cSmrg .real_widget = 0 459dedec0cSmrg }; 469dedec0cSmrg WidgetInfo out = { 0, NULL, 0 }; 479dedec0cSmrg 489dedec0cSmrg _XEditResResetStream(&ps); 499dedec0cSmrg 509dedec0cSmrg _XEditResPut8(&ps, 8); 519dedec0cSmrg _XEditResPut16(&ps, 16); 529dedec0cSmrg _XEditResPut16(&ps, 0xface); 539dedec0cSmrg _XEditResPut32(&ps, 32); 549dedec0cSmrg _XEditResPut32(&ps, 0xbabeface); 559dedec0cSmrg _XEditResPutString8(&ps, test_string); 569dedec0cSmrg _XEditResPutWidgetInfo(&ps, &i); 579dedec0cSmrg 589dedec0cSmrg /* current is a pointer to the next byte to read from or write to, 599dedec0cSmrg so we need to reset it to the beginning to read the data we wrote */ 609dedec0cSmrg ps.current = ps.top; 619dedec0cSmrg 629dedec0cSmrg res = _XEditResGet8(&ps, &c); 639dedec0cSmrg assert(res == True); 649dedec0cSmrg assert(c == 8); 659dedec0cSmrg 669dedec0cSmrg res = _XEditResGet16(&ps, &s); 679dedec0cSmrg assert(res == True); 689dedec0cSmrg assert(s == 16); 699dedec0cSmrg 709dedec0cSmrg res = _XEditResGet16(&ps, &s); 719dedec0cSmrg assert(res == True); 729dedec0cSmrg assert(s == 0xface); 739dedec0cSmrg 749dedec0cSmrg /* set the full value so we can make sure that in 64-bit mode we 759dedec0cSmrg write to the full long value, not just 32-bits of it. */ 769dedec0cSmrg memset(&l, 0x0f, sizeof(l)); 779dedec0cSmrg res = _XEditResGet32(&ps, &l); 789dedec0cSmrg assert(res == True); 799dedec0cSmrg assert(l == 32); 809dedec0cSmrg 819dedec0cSmrg memset(&l, 0x0f, sizeof(l)); 829dedec0cSmrg res = _XEditResGet32(&ps, &l); 839dedec0cSmrg assert(res == True); 849dedec0cSmrg assert(l == 0xbabeface); 859dedec0cSmrg 869dedec0cSmrg res = _XEditResGetString8(&ps, &str); 879dedec0cSmrg assert(res == True); 889dedec0cSmrg assert(strcmp(str, test_string) == 0); 899dedec0cSmrg XtFree(str); 909dedec0cSmrg str = NULL; 919dedec0cSmrg 929dedec0cSmrg res = _XEditResGetWidgetInfo(&ps, &out); 939dedec0cSmrg assert(res == True); 949dedec0cSmrg assert(memcmp(ids, out.ids, sizeof(ids)) == 0); 959dedec0cSmrg XtFree((char *) out.ids); 969dedec0cSmrg out.ids = NULL; 979dedec0cSmrg 989dedec0cSmrg return 0; 999dedec0cSmrg} 100