1999-01-22 20:53:35 +03:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-22 20:53:35 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-01-22 20:53:35 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-01-22 20:53:35 +03:00
|
|
|
|
|
|
|
/* Test the structure creation and serialization APIs from xpt_struct.c */
|
1999-05-27 03:20:24 +04:00
|
|
|
#include <stdio.h>
|
1999-01-22 20:53:35 +03:00
|
|
|
|
|
|
|
#include "xpt_xdr.h"
|
|
|
|
#include "xpt_struct.h"
|
|
|
|
|
|
|
|
#define PASS(msg) \
|
|
|
|
fprintf(stderr, "PASSED : %s\n", msg);
|
|
|
|
|
|
|
|
#define FAIL(msg) \
|
|
|
|
fprintf(stderr, "FAILURE: %s\n", msg);
|
|
|
|
|
|
|
|
#define TRY_(msg, cond, silent) \
|
|
|
|
if ((cond) && !silent) { \
|
|
|
|
PASS(msg); \
|
|
|
|
} else { \
|
|
|
|
FAIL(msg); \
|
|
|
|
return 1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TRY(msg, cond) TRY_(msg, cond, 0)
|
|
|
|
#define TRY_Q(msg, cond) TRY_(msg, cond, 1);
|
|
|
|
|
1999-01-25 22:36:48 +03:00
|
|
|
struct nsID iid = {
|
1999-01-22 20:53:35 +03:00
|
|
|
0x00112233,
|
|
|
|
0x4455,
|
|
|
|
0x6677,
|
1999-01-25 22:36:48 +03:00
|
|
|
{0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}
|
|
|
|
};
|
|
|
|
|
1999-09-20 11:27:51 +04:00
|
|
|
XPTTypeDescriptor td_void;
|
1999-01-22 20:53:35 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
2000-04-20 12:52:05 +04:00
|
|
|
XPTArena *arena;
|
1999-01-22 20:53:35 +03:00
|
|
|
XPTHeader *header;
|
1999-01-25 22:36:48 +03:00
|
|
|
XPTAnnotation *ann;
|
1999-01-22 20:53:35 +03:00
|
|
|
XPTInterfaceDescriptor *id;
|
1999-01-25 22:36:48 +03:00
|
|
|
XPTMethodDescriptor *meth;
|
1999-01-22 20:53:35 +03:00
|
|
|
|
|
|
|
XPTState *state;
|
|
|
|
XPTCursor curs, *cursor = &curs;
|
1999-01-27 09:32:57 +03:00
|
|
|
char *data, *head;
|
1999-01-22 20:53:35 +03:00
|
|
|
FILE *out;
|
|
|
|
uint32 len, header_sz;
|
|
|
|
|
|
|
|
PRBool ok;
|
1999-02-16 21:41:30 +03:00
|
|
|
|
|
|
|
td_void.prefix.flags = TD_VOID;
|
1999-04-04 04:13:28 +04:00
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
if (argc == 0) {
|
|
|
|
static char* args[] = { "SimpleTypeLib", "simple.xpt", NULL };
|
|
|
|
argc = 2;
|
|
|
|
argv = args;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-01-22 20:53:35 +03:00
|
|
|
if (argc != 2) {
|
|
|
|
fprintf(stderr, "Usage: %s <filename.xpt>\n"
|
|
|
|
" Creates a simple typelib file.\n", argv[0]);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-04-20 12:52:05 +04:00
|
|
|
arena = XPT_NewArena(1024, sizeof(double), "main");
|
|
|
|
TRY("XPT_NewArena", arena);
|
|
|
|
|
1999-01-22 20:53:35 +03:00
|
|
|
/* construct a header */
|
2000-04-20 12:52:05 +04:00
|
|
|
header = XPT_NewHeader(arena, 1);
|
1999-01-22 20:53:35 +03:00
|
|
|
TRY("NewHeader", header);
|
|
|
|
|
1999-01-25 22:36:48 +03:00
|
|
|
|
2000-04-20 12:52:05 +04:00
|
|
|
ann = XPT_NewAnnotation(arena, XPT_ANN_LAST | XPT_ANN_PRIVATE,
|
|
|
|
XPT_NewStringZ(arena, "SimpleTypeLib 1.0"),
|
|
|
|
XPT_NewStringZ(arena, "See You In Rome"));
|
1999-01-25 22:36:48 +03:00
|
|
|
TRY("NewAnnotation", ann);
|
|
|
|
header->annotations = ann;
|
1999-01-22 20:53:35 +03:00
|
|
|
|
|
|
|
header_sz = XPT_SizeOfHeaderBlock(header);
|
|
|
|
|
2000-04-20 12:52:05 +04:00
|
|
|
id = XPT_NewInterfaceDescriptor(arena, 0, 2, 2, 0);
|
1999-01-22 20:53:35 +03:00
|
|
|
TRY("NewInterfaceDescriptor", id);
|
|
|
|
|
2000-04-20 12:52:05 +04:00
|
|
|
ok = XPT_FillInterfaceDirectoryEntry(arena, header->interface_directory, &iid,
|
1999-04-07 04:29:49 +04:00
|
|
|
"Interface", "NS", id);
|
1999-01-22 20:53:35 +03:00
|
|
|
TRY("FillInterfaceDirectoryEntry", ok);
|
|
|
|
|
1999-01-25 22:36:48 +03:00
|
|
|
/* void method1(void) */
|
|
|
|
meth = &id->method_descriptors[0];
|
2000-04-20 12:52:05 +04:00
|
|
|
ok = XPT_FillMethodDescriptor(arena, meth, 0, "method1", 0);
|
1999-01-25 22:36:48 +03:00
|
|
|
TRY("FillMethodDescriptor", ok);
|
|
|
|
meth->result->flags = 0;
|
|
|
|
meth->result->type.prefix.flags = TD_VOID;
|
|
|
|
|
|
|
|
/* wstring method2(in uint32, in bool) */
|
|
|
|
meth = &id->method_descriptors[1];
|
2000-04-20 12:52:05 +04:00
|
|
|
ok = XPT_FillMethodDescriptor(arena, meth, 0, "method2", 2);
|
1999-01-25 22:36:48 +03:00
|
|
|
TRY("FillMethodDescriptor", ok);
|
|
|
|
|
|
|
|
meth->result->flags = 0;
|
2001-01-26 05:32:18 +03:00
|
|
|
meth->result->type.prefix.flags = TD_PSTRING | XPT_TDP_POINTER;
|
1999-01-25 22:36:48 +03:00
|
|
|
meth->params[0].type.prefix.flags = TD_UINT32;
|
|
|
|
meth->params[0].flags = XPT_PD_IN;
|
|
|
|
meth->params[1].type.prefix.flags = TD_BOOL;
|
|
|
|
meth->params[1].flags = XPT_PD_IN;
|
|
|
|
|
2001-01-26 05:32:18 +03:00
|
|
|
#if 0
|
1999-01-26 22:31:25 +03:00
|
|
|
/* const one = 1; */
|
|
|
|
id->const_descriptors[0].name = "one";
|
|
|
|
id->const_descriptors[0].type.prefix.flags = TD_UINT16;
|
|
|
|
id->const_descriptors[0].value.ui16 = 1;
|
|
|
|
|
|
|
|
/* const squeamish = "ossifrage"; */
|
|
|
|
id->const_descriptors[1].name = "squeamish";
|
|
|
|
id->const_descriptors[1].type.prefix.flags = TD_PBSTR | XPT_TDP_POINTER;
|
2000-04-20 12:52:05 +04:00
|
|
|
id->const_descriptors[1].value.string = XPT_NewStringZ(arena, "ossifrage");
|
2001-01-26 05:32:18 +03:00
|
|
|
#endif
|
1999-01-26 22:31:25 +03:00
|
|
|
|
1999-01-22 20:53:35 +03:00
|
|
|
/* serialize it */
|
|
|
|
state = XPT_NewXDRState(XPT_ENCODE, NULL, 0);
|
|
|
|
TRY("NewState (ENCODE)", state);
|
|
|
|
|
|
|
|
ok = XPT_MakeCursor(state, XPT_HEADER, header_sz, cursor);
|
|
|
|
TRY("MakeCursor", ok);
|
|
|
|
|
2000-04-20 12:52:05 +04:00
|
|
|
ok = XPT_DoHeader(arena, cursor, &header);
|
1999-01-22 20:53:35 +03:00
|
|
|
TRY("DoHeader", ok);
|
|
|
|
|
1999-02-18 05:53:08 +03:00
|
|
|
out = fopen(argv[1], "wb");
|
1999-01-25 22:36:48 +03:00
|
|
|
if (!out) {
|
|
|
|
perror("FAILED: fopen");
|
|
|
|
return 1;
|
|
|
|
}
|
1999-01-22 20:53:35 +03:00
|
|
|
|
1999-01-27 09:32:57 +03:00
|
|
|
XPT_GetXDRData(state, XPT_HEADER, &head, &len);
|
|
|
|
fwrite(head, len, 1, out);
|
1999-01-22 20:53:35 +03:00
|
|
|
|
|
|
|
XPT_GetXDRData(state, XPT_DATA, &data, &len);
|
|
|
|
fwrite(data, len, 1, out);
|
1999-01-27 09:32:57 +03:00
|
|
|
|
1999-02-16 21:41:30 +03:00
|
|
|
if (ferror(out) != 0 || fclose(out) != 0) {
|
|
|
|
fprintf(stderr, "\nError writing file: %s\n\n", argv[1]);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr, "\nFile written: %s\n\n", argv[1]);
|
|
|
|
}
|
|
|
|
XPT_DestroyXDRState(state);
|
|
|
|
|
2000-04-20 12:52:05 +04:00
|
|
|
XPT_FreeHeader(arena, header);
|
|
|
|
XPT_DestroyArena(arena);
|
|
|
|
|
1999-01-22 20:53:35 +03:00
|
|
|
return 0;
|
|
|
|
}
|
1999-01-27 09:32:57 +03:00
|
|
|
|