tst.chasestrings.c revision 266989
164562Sgshapiro/*
264562Sgshapiro * This file and its contents are supplied under the terms of the
3223067Sgshapiro * Common Development and Distribution License ("CDDL"), version 1.0.
464562Sgshapiro * You may only use this file in accordance with the terms of version
564562Sgshapiro * 1.0 of the CDDL.
664562Sgshapiro *
764562Sgshapiro * A full copy of the text of the CDDL should have accompanied this
864562Sgshapiro * source.  A copy of the CDDL is also available via the Internet at
964562Sgshapiro * http://www.illumos.org/license/CDDL.
1064562Sgshapiro */
1164562Sgshapiro
1264562Sgshapiro/*
13244833Sgshapiro * Copyright 2013 (c) Joyent, Inc. All rights reserved.
1464562Sgshapiro */
1564562Sgshapiro
1664562Sgshapiro/*
1764562Sgshapiro * This test takes data from the current binary which is basically running in a
1864562Sgshapiro * loop between two functions and our goal is to have two unique types that they
19132943Sgshapiro * contain which we can print.
2064562Sgshapiro */
2164562Sgshapiro
2264562Sgshapiro#include <unistd.h>
2364562Sgshapiro
2464562Sgshapirotypedef struct zelda_info {
25132943Sgshapiro	char	*zi_gamename;
2664562Sgshapiro	int	zi_ndungeons;
2764562Sgshapiro	char	*zi_villain;
28132943Sgshapiro	int	zi_haszelda;
2990792Sgshapiro} zelda_info_t;
3090792Sgshapiro
3190792Sgshapirostatic int
3290792Sgshapirohas_princess(zelda_info_t *z)
33132943Sgshapiro{
34132943Sgshapiro	return (z->zi_haszelda);
35132943Sgshapiro}
36132943Sgshapiro
37132943Sgshapirostatic int
3864562Sgshapirohas_dungeons(zelda_info_t *z)
3964562Sgshapiro{
4064562Sgshapiro	return (z->zi_ndungeons != 0);
4194334Sgshapiro}
42223067Sgshapiro
4364562Sgshapirostatic const char *
4464562Sgshapirohas_villain(zelda_info_t *z)
4594334Sgshapiro{
46223067Sgshapiro	return (z->zi_villain);
47}
48
49int
50main(void)
51{
52	zelda_info_t oot;
53	zelda_info_t la;
54	zelda_info_t lttp;
55
56	oot.zi_gamename = "Ocarina of Time";
57	oot.zi_ndungeons = 10;
58	oot.zi_villain = "Ganondorf";
59	oot.zi_haszelda = 1;
60
61	la.zi_gamename = "Link's Awakening";
62	la.zi_ndungeons = 9;
63	la.zi_villain = "Nightmare";
64	la.zi_haszelda = 0;
65
66	lttp.zi_gamename = "A Link to the Past";
67	lttp.zi_ndungeons = 12;
68	lttp.zi_villain = "Ganon";
69	lttp.zi_haszelda = 1;
70
71	for (;;) {
72		(void) has_princess(&oot);
73		(void) has_dungeons(&la);
74		(void) has_villain(&lttp);
75		sleep(1);
76	}
77
78	return (0);
79}
80