Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9d57562

Browse files
Edmund MerglEdmund Mergl
Edmund Mergl
authored and
Edmund Mergl
committed
*** empty log message ***
1 parent5ec6055 commit9d57562

File tree

1 file changed

+265
-0
lines changed

1 file changed

+265
-0
lines changed

‎src/interfaces/perl5/test.pl

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
#!/usr/local/bin/perl
2+
3+
#-------------------------------------------------------
4+
#
5+
# $Id: test.pl,v 1.4 1997/09/17 20:53:35 mergl Exp $
6+
#
7+
# Copyright (c) 1997 Edmund Mergl
8+
#
9+
#-------------------------------------------------------
10+
11+
# Before `make install' is performed this script should be runnable with
12+
# `make test'. After `make install' it should work as `perl test.pl'
13+
14+
######################### We start with some black magic to print on failure.
15+
16+
BEGIN {$| = 1;print"1..50\n"; }
17+
END {print"not ok 1\n"unless$loaded;}
18+
use Pg;
19+
$loaded = 1;
20+
print"ok 1\n";
21+
22+
######################### End of black magic.
23+
24+
$dbmain ='template1';
25+
$dbname ='pgperltest';
26+
$trace ='/tmp/pgtrace.out';
27+
$cnt = 2;
28+
$DEBUG = 0;# set this to 1 for traces
29+
30+
$| = 1;
31+
32+
######################### the following methods will be tested
33+
34+
#connectdb
35+
#db
36+
#user
37+
#host
38+
#port
39+
#finish
40+
#status
41+
#errorMessage
42+
#trace
43+
#untrace
44+
#exec
45+
#getline
46+
#endcopy
47+
#putline
48+
#resultStatus
49+
#ntuples
50+
#nfields
51+
#fname
52+
#fnumber
53+
#ftype
54+
#fsize
55+
#cmdStatus
56+
#oidStatus
57+
#cmdTuples
58+
#getvalue
59+
60+
######################### the following methods will not be tested
61+
62+
#setdb
63+
#conndefaults
64+
#reset
65+
#options
66+
#tty
67+
#getlength
68+
#getisnull
69+
#print
70+
#notifies
71+
#displayTuples
72+
#printTuples
73+
#lo_import
74+
#lo_export
75+
#lo_unlink
76+
#lo_open
77+
#lo_close
78+
#lo_read
79+
#lo_write
80+
#lo_creat
81+
#lo_seek
82+
#lo_tell
83+
84+
######################### handles error condition
85+
86+
$SIG{PIPE} =sub {print"broken pipe\n" };
87+
88+
######################### create and connect to test database
89+
# 2-4
90+
91+
$conn = Pg::connectdb("dbname =$dbmain");
92+
cmp_eq(PGRES_CONNECTION_OK,$conn->status);
93+
94+
# might fail if $dbname doesn't exist => don't check resultStatus
95+
$result =$conn->exec("DROP DATABASE$dbname");
96+
97+
$result =$conn->exec("CREATE DATABASE$dbname");
98+
cmp_eq(PGRES_COMMAND_OK,$result->resultStatus);
99+
100+
$conn = Pg::connectdb("dbname =$dbname");
101+
cmp_eq(PGRES_CONNECTION_OK,$conn->status);
102+
103+
######################### debug, PQtrace
104+
105+
if ($DEBUG) {
106+
open(TRACE,">$trace") ||die"can not open$trace:$!";
107+
$conn->trace(TRACE);
108+
}
109+
110+
######################### check PGconn
111+
# 5-8
112+
113+
$db =$conn->db;
114+
cmp_eq($dbname,$db);
115+
116+
$user =$conn->user;
117+
cmp_ne("",$user);
118+
119+
$host =$conn->host;
120+
cmp_ne("",$host);
121+
122+
$port =$conn->port;
123+
cmp_ne("",$port);
124+
125+
######################### create and insert into table
126+
# 9-20
127+
128+
$result =$conn->exec("CREATE TABLE person (id int4, name char16)");
129+
cmp_eq(PGRES_COMMAND_OK,$result->resultStatus);
130+
cmp_eq("CREATE",$result->cmdStatus);
131+
132+
for ($i = 1;$i <= 5;$i++) {
133+
$result =$conn->exec("INSERT INTO person VALUES ($i, 'Edmund Mergl')");
134+
cmp_eq(PGRES_COMMAND_OK,$result->resultStatus);
135+
cmp_ne(0,$result->oidStatus);
136+
}
137+
138+
######################### copy to stdout, PQgetline
139+
# 21-27
140+
141+
$result =$conn->exec("COPY person TO STDOUT");
142+
cmp_eq(PGRES_COPY_OUT,$result->resultStatus);
143+
144+
$i = 1;
145+
while (-1 !=$ret) {
146+
$ret =$conn->getline($string, 256);
147+
lastif$stringeq"\\.";
148+
cmp_eq("$iEdmund Mergl",$string);
149+
$i ++;
150+
}
151+
152+
cmp_eq(0,$conn->endcopy);
153+
154+
######################### delete and copy from stdin, PQputline
155+
# 28-34
156+
157+
$result =$conn->exec("BEGIN");
158+
cmp_eq(PGRES_COMMAND_OK,$result->resultStatus);
159+
160+
$result =$conn->exec("DELETE FROM person");
161+
cmp_eq(PGRES_COMMAND_OK,$result->resultStatus);
162+
cmp_eq("DELETE 5",$result->cmdStatus);
163+
cmp_eq("5",$result->cmdTuples);
164+
165+
$result =$conn->exec("COPY person FROM STDIN");
166+
cmp_eq(PGRES_COPY_IN,$result->resultStatus);
167+
168+
for ($i = 1;$i <= 5;$i++) {
169+
# watch the tabs and do not forget the newlines
170+
$conn->putline("$iEdmund Mergl\n");
171+
}
172+
$conn->putline("\\.\n");
173+
174+
cmp_eq(0,$conn->endcopy);
175+
176+
$result =$conn->exec("END");
177+
cmp_eq(PGRES_COMMAND_OK,$result->resultStatus);
178+
179+
######################### select from person, PQgetvalue
180+
# 35-48
181+
182+
$result =$conn->exec("SELECT * FROM person");
183+
cmp_eq(PGRES_TUPLES_OK,$result->resultStatus);
184+
185+
for ($k = 0;$k <$result->nfields;$k++) {
186+
$fname =$result->fname($k);
187+
$ftype =$result->ftype($k);
188+
$fsize =$result->fsize($k);
189+
if (0 ==$k) {
190+
cmp_eq("id",$fname);
191+
cmp_eq(23,$ftype);
192+
cmp_eq(4,$fsize);
193+
}else {
194+
cmp_eq("name",$fname);
195+
cmp_eq(20,$ftype);
196+
cmp_eq(16,$fsize);
197+
}
198+
$fnumber =$result->fnumber($fname);
199+
cmp_eq($k,$fnumber);
200+
}
201+
202+
for ($k = 0;$k <$result->ntuples;$k++) {
203+
$string ="";
204+
for ($l = 0;$l <$result->nfields;$l++) {
205+
$string .=$result->getvalue($k,$l) ."";
206+
}
207+
$i =$k + 1;
208+
cmp_eq("$i Edmund Mergl",$string);
209+
}
210+
211+
######################### debug, PQuntrace
212+
213+
if ($DEBUG) {
214+
close(TRACE) ||die"bad TRACE:$!";
215+
$conn->untrace;
216+
}
217+
218+
######################### disconnect and drop test database
219+
# 49-50
220+
221+
$conn = Pg::connectdb("dbname =$dbmain");
222+
cmp_eq(PGRES_CONNECTION_OK,$conn->status);
223+
224+
$result =$conn->exec("DROP DATABASE$dbname");
225+
cmp_eq(PGRES_COMMAND_OK,$result->resultStatus);
226+
227+
######################### hopefully
228+
229+
print"test sequence finished.\n"if 51 ==$cnt;
230+
231+
######################### utility functions
232+
233+
subcmp_eq {
234+
235+
my$cmp =shift;
236+
my$ret =shift;
237+
my$msg;
238+
239+
if ("$cmp"eq"$ret") {
240+
print"ok$cnt\n";
241+
}else {
242+
$msg =$conn->errorMessage;
243+
print"not ok$cnt:$cmp,$ret\n$msg\n";
244+
exit;
245+
}
246+
$cnt++;
247+
}
248+
249+
subcmp_ne {
250+
251+
my$cmp =shift;
252+
my$ret =shift;
253+
my$msg;
254+
255+
if ("$cmp"ne"$ret") {
256+
print"ok$cnt\n";
257+
}else {
258+
$msg =$conn->errorMessage;
259+
print"not ok$cnt:$cmp,$ret\n$msg\n";
260+
exit;
261+
}
262+
$cnt++;
263+
}
264+
265+
######################### EOF

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp