xref: /illumos-gate/usr/src/cmd/dtrace/test/tst/common/funcs/tst.strtok.d (revision dbed73cbda2229fd1aa6dc5743993cae7f0a7ee9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #pragma D option quiet
30 
31 BEGIN
32 {
33 	this->str = ",,,Carrots,,Barley,Oatmeal,,,Beans,";
34 }
35 
36 BEGIN
37 /(this->field = strtok(this->str, ",")) == NULL/
38 {
39 	exit(1);
40 }
41 
42 BEGIN
43 {
44 	printf("%s\n", this->field);
45 }
46 
47 BEGIN
48 /(this->field = strtok(NULL, ",")) == NULL/
49 {
50 	exit(2);
51 }
52 
53 BEGIN
54 {
55 	printf("%s\n", this->field);
56 }
57 
58 BEGIN
59 /(this->field = strtok(NULL, ",")) == NULL/
60 {
61 	exit(3);
62 }
63 
64 BEGIN
65 {
66 	printf("%s\n", this->field);
67 }
68 
69 BEGIN
70 /(this->field = strtok(NULL, ",")) == NULL/
71 {
72 	exit(4);
73 }
74 
75 BEGIN
76 {
77 	printf("%s\n", this->field);
78 }
79 
80 BEGIN
81 /(self->a = strtok(NULL, ",")) != NULL/
82 {
83 	printf("unexpected field: %s\n", this->field);
84 	exit(5);
85 }
86 
87 struct {
88 	string s1;
89 	string s2;
90 	string result;
91 } command[int];
92 
93 int i;
94 
95 BEGIN
96 {
97 	command[i].s1 = "";
98 	command[i].s2 = "";
99 	command[i].result = "";
100 	i++;
101 
102 	command[i].s1 = "foo";
103 	command[i].s2 = "";
104 	command[i].result = command[i].s1;
105 	i++;
106 
107 	command[i].s1 = "foobar";
108 	command[i].s2 = "o";
109 	command[i].result = "f";
110 	i++;
111 
112 	command[i].s1 = "oobar";
113 	command[i].s2 = "o";
114 	command[i].result = "bar";
115 	i++;
116 
117 	command[i].s1 = "foo";
118 	command[i].s2 = "bar";
119 	command[i].result = command[i].s1;
120 	i++;
121 
122 	command[i].s1 = "";
123 	command[i].s2 = "foo";
124 	command[i].result = "";
125 	i++;
126 
127 	end = i;
128 	i = 0;
129 }
130 
131 tick-1ms
132 /i < end &&
133     (this->result = strtok(command[i].s1, command[i].s2)) != command[i].result/
134 {
135 	printf("strtok(\"%s\", \"%s\") = \"%s\", expected \"%s\"",
136 	    command[i].s1, command[i].s2,
137 	    this->result != NULL ? this->result : "<null>",
138 	    command[i].result != NULL ? command[i].result : "<null>");
139 	exit(6 + i);
140 }
141 
142 tick-1ms
143 /++i == end/
144 {
145 	exit(0);
146 }
147