From: Darren Chamberlain Date: Fri, 15 Mar 2002 20:10:22 +0000 (+0000) Subject: Added test data in groovy hierarchical directories. X-Git-Tag: v0.01~58^2~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0494e6729c85162cd84131e60871fa428196947d;p=dbsrgits%2FSQL-Translator.git Added test data in groovy hierarchical directories. Added some basic tests, many of which don't do much yet. --- diff --git a/t/02mysql-parser.t b/t/02mysql-parser.t new file mode 100644 index 0000000..19a672c --- /dev/null +++ b/t/02mysql-parser.t @@ -0,0 +1,27 @@ +#!/usr/bin/perl +# vim: set ft=perl: +# +# NOTE!!!! +# For now, all this is testing is that Parse::RecDescent does not +# die with an error! I am not verifying the validity of the data +# returned here, just that the parser actually completed its parsing! +# + +use Symbol; +use Data::Dumper; +use SQL::Translator::Parser::MySQL qw(parse); + +my $datafile = "t/data/mysql/Apache-Session-MySQL.sql"; +my $data; +my $fh = gensym; + +open $fh, $datafile or die "Can't open '$datafile' for reading: $!"; +read($fh, $data, -s $datafile); +close $fh or die "Can't close '$datafile': $!"; + +BEGIN { print "1..1\n"; } + +eval { parse($data); }; + +print "not " if $@; +print "ok 1\n"; diff --git a/t/03mysql-to-oracle.t b/t/03mysql-to-oracle.t new file mode 100644 index 0000000..53f7e9d --- /dev/null +++ b/t/03mysql-to-oracle.t @@ -0,0 +1,23 @@ +#!/usr/local/bin/perl +# vim: set ft=perl: + +BEGIN { print "1..1\n" } + +my $create = q| +CREATE TABLE random ( + id int auto_increment PRIMARY KEY, + foo varchar(255) not null default '', + updated timestamp +); +|; + +use SQL::Translator; +use Data::Dumper; + +my $tr = SQL::Translator->new(parser => "MySQL", + producer => "Oracle" + #producer => "SQL::Translator::Producer::Oracle::translate" + #producer => sub { Dumper($_[1]) } + ); + +print $tr->translate(\$create); diff --git a/t/04file,fh,string.t b/t/04file,fh,string.t new file mode 100644 index 0000000..ca768be --- /dev/null +++ b/t/04file,fh,string.t @@ -0,0 +1,78 @@ +#!/usr/bin/perl +# vim: set ft=perl: +# +# This tests that the same file can be passed in using a filename, +# a filehandle, and a string, and return identical results. There's +# a lot of setup here, because we have to emulate the various ways +# that $tr->translate might be called: with a string (filename), +# with a filehandle (IO::File, FileHandle, or \*FOO), and with a +# scalar reference (data in a string). +# + +use strict; + +use IO::File; +use SQL::Translator; + +# How many tests +BEGIN { print "1..3\n"; } + +# Our object. +my $tr = SQL::Translator->new(parser => "MySQL", producer => "Oracle"); + +# The filename, holder for all the data, and the filehandle +my $datafile = "t/data/mysql/Apache-Session-MySQL.sql"; +my $data; +my $fh = IO::File->new($datafile); + +# Pass filename: simplest way +my $translated_datafile = $tr->translate($datafile); +print "Data from filename method is\n$translated_datafile\n\n\n"; + +# Pass string reference +read($fh, $data, -s $datafile); +my $translated_data = $tr->translate(\$data); +print "Data from string is\n$translated_data\n\n\n"; + + +# Pass IO::File instance +$fh->setpos(0); +my $translated_fh = $tr->translate($fh); +print "Data from filehandle method is\n$translated_fh\n\n\n"; + +# With all that setup out of the way, we can perform the actual tests. +# We need to test the equality of: +# +# filename and string +# filename and filehandle +# filehandle and string +# +# And then we have all possibilities. Note that the order in which +# the comparison is done is pretty arbitrary, and doesn't affect the +# outcomes. Similarly, the order of the eq tests is also unimportant. +# +print "not " unless ($translated_datafile eq $translated_fh); +print "ok 1 # from file == from filehandle\n"; + +print "not " unless ($translated_datafile eq $translated_data); +print "ok 2 # from file == from string\n"; + +print "not " unless ($translated_data eq $translated_fh); +print "ok 3 # from string == from filehandle\n"; +# +# Problem with SQL::Translator::Producer::Oracle: it is keeping track of +# the last sequence number used, so as not to duplicate them, which +# is reasonable. However on runs past the first, it seems to be +# creating multiple constraint lines, that look like: +# +# CONSTRAINT i_sessions_pk_2 PRIMARY KEY (id), +# CONSTRAINT i_sessions_pk_3 PRIMARY KEY (id) +# +# Dunno why. + +# For this test, we should devise some other sort of output routine, +# that can take a data structure and output it in a reasonable -- and +# machine parsable! -- way. The tendency of ::Producer::Oracle to +# produce numerically incrementing constraints is fine, and is not a +# bug, but it makes this test fail. (The duplicate CONSTRAINT *is* a +# bug, though.) diff --git a/t/data/mysql/Apache-Session-MySQL.sql b/t/data/mysql/Apache-Session-MySQL.sql new file mode 100644 index 0000000..7f0b417 --- /dev/null +++ b/t/data/mysql/Apache-Session-MySQL.sql @@ -0,0 +1,6 @@ +# Taken from Apache::Session::MySQL +CREATE TABLE sessions ( + id char(32) not null primary key, + a_session text +); + diff --git a/t/data/mysql/BGEP-RE-create.sql b/t/data/mysql/BGEP-RE-create.sql new file mode 100644 index 0000000..a37f26e --- /dev/null +++ b/t/data/mysql/BGEP-RE-create.sql @@ -0,0 +1,209 @@ +## MySQL dump 7.1 +## +## Host: db1-3.23.32 Database: RE +## -------------------------------------------------------- +## Server version 3.23.32 + + +## Table structure for table 'ad' {{{ +## +DROP TABLE IF EXISTS ad; +CREATE TABLE ad ( +## DROP TABLE IF EXISTS listing; +## CREATE TABLE listing ( + id varchar(32) DEFAULT '' NOT NULL, + -- lid varchar(32) DEFAULT '' NOT NULL, + vendor_id varchar(32) DEFAULT '' NOT NULL, + -- lvid varchar(32) DEFAULT '' NOT NULL, + realtor_id int(11) DEFAULT '0' NOT NULL, + -- rid int(11) DEFAULT '0' NOT NULL, + location_id int(11) DEFAULT '0' NOT NULL, + -- lcid int(11) DEFAULT '0' NOT NULL, + origin_id int(11) DEFAULT '0' NOT NULL, + -- oid int(11) DEFAULT '0' NOT NULL, + style_id int(11) DEFAULT '0' NOT NULL, + -- sid int(11) DEFAULT '0' NOT NULL, + style varchar(42) DEFAULT '' NOT NULL, + media_code_id int(11) DEFAULT '0' NOT NULL, + -- mcid int(11) DEFAULT '0' NOT NULL, + priority int(11) DEFAULT '1' NOT NULL, + listing_date date, + price int(11) DEFAULT '0' NOT NULL, + rooms int(11) DEFAULT '0' NOT NULL, + bedrooms int(11) DEFAULT '0' NOT NULL, + fullbaths int(11) DEFAULT '0' NOT NULL, + halfbaths int(11) DEFAULT '0' NOT NULL, + amenities varchar(255) DEFAULT '' NOT NULL, + lotsize int(11) DEFAULT '0' NOT NULL, + openhouse tinyint(4) DEFAULT '0' NOT NULL, + street varchar(255) DEFAULT '' NOT NULL, + no_units tinyint DEFAULT 1 NOT NULL, + ad_text text, + original_ad_text text, + photo varchar(255) DEFAULT '' NOT NULL, + thumbnail varchar(255) DEFAULT '' NOT NULL, + PRIMARY KEY (id), + -- PRIMARY KEY (lid), + KEY vendor_id_idx (vendor_id), + -- KEY vendor_id_idx (vid), + KEY amenities_idx (amenities), + KEY listing_date_idx (listing_date), + FULLTEXT ad_text_search (ad_text) +); +## }}} + +## Table structure for table 'ad_to_amenity' {{{ +## +DROP TABLE IF EXISTS ad_to_amenity; +CREATE TABLE ad_to_amenity ( +## CREATE TABLE listing_to_amenity ( + id int(11) NOT NULL auto_increment, + -- aaid int(11) NOT NULL auto_increment, + ad_id char(32) DEFAULT '' NOT NULL, + -- lid char(32) DEFAULT '' NOT NULL, + amenity_id int(11) DEFAULT '0' NOT NULL, + -- aid int(11) DEFAULT '0' NOT NULL, + PRIMARY KEY (id), + -- PRIMARY KEY (aaid), + KEY ad_id_idx (ad_id) + -- KEY ad_id_idx (lid) +); +## }}} + +## Table structure for table 'amenity' {{{ +## +DROP TABLE IF EXISTS amenity; +CREATE TABLE amenity ( + id int(11) NOT NULL auto_increment, + -- aid int(11) NOT NULL auto_increment, + amenity varchar(42) DEFAULT '' NOT NULL, + abbrev varchar(4) DEFAULT '' NOT NULL, + -- abbrev char(4) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + -- PRIMARY KEY (aid) +); +## }}} + +## Table structure for table 'email' {{{ +## +DROP TABLE IF EXISTS email; +CREATE TABLE email ( + id int(11) NOT NULL auto_increment, + -- eid int(11) NOT NULL auto_increment, + realtor_id int(11) DEFAULT '0' NOT NULL, + property_id int(11) DEFAULT '0' NOT NULL, + firstname varchar(42) DEFAULT '' NOT NULL, + lastname varchar(42) DEFAULT '' NOT NULL, + phone varchar(10) DEFAULT '' NOT NULL, + timeframe varchar(255) DEFAULT '' NOT NULL, + schedule_appt tinyint(4) DEFAULT '0' NOT NULL, + date_sent timestamp(14), + comments text, + PRIMARY KEY (id) + -- PRIMARY KEY (eid) +); +## }}} + +## Table structure for table 'history' {{{ +## +DROP TABLE IF EXISTS history; +CREATE TABLE history ( + id int(11) NOT NULL auto_increment, + -- hid int(11) NOT NULL auto_increment, + type varchar(42) DEFAULT '' NOT NULL, + value varchar(255) DEFAULT '' NOT NULL, + ts timestamp(14), + PRIMARY KEY (id) + -- PRIMARY KEY (hid) +); +## }}} + +## Table structure for table 'location' {{{ +## +DROP TABLE IF EXISTS location; +CREATE TABLE location ( + id int(11) NOT NULL auto_increment, + -- lcid int(11) NOT NULL auto_increment, + abbrev varchar(4) DEFAULT '' NOT NULL, + city varchar(42) DEFAULT '' NOT NULL, + state char(2) DEFAULT 'MA' NOT NULL, + fullstate varchar(42) DEFAULT 'Massachusetts' NOT NULL, + PRIMARY KEY (id), + -- PRIMARY KEY (lcid), + KEY city_idx (city), + KEY abbrev_idx (abbrev), + KEY state_idx (state) +); +## }}} + +## Table structure for table 'media_code' {{{ +## +DROP TABLE IF EXISTS media_code; +CREATE TABLE media_code ( +## DROP TABLE IF EXISTS mediacode; +## CREATE TABLE mediacode ( -- should this table be category? + media_code int(11) DEFAULT '700' NOT NULL, + -- mcid int(11) DEFAULT '700' NOT NULL, + classification varchar(42) DEFAULT '' NOT NULL, + PRIMARY KEY (media_code) + -- PRIMARY KEY (mcid) +); +## }}} + +## Table structure for table 'origin' {{{ +## +DROP TABLE IF EXISTS origin; +CREATE TABLE origin ( + id int(11) NOT NULL auto_increment, + -- oid int(11) NOT NULL auto_increment, + origin varchar(24) DEFAULT '' NOT NULL, + display varchar(42) DEFAULT '' NOT NULL, + PRIMARY KEY (id) + -- PRIMARY KEY (oid) +); +## }}} + +## Table structure for table 'realtor' {{{ +## +DROP TABLE IF EXISTS realtor; +CREATE TABLE realtor ( + id int(11) NOT NULL auto_increment, + -- rid int(11) NOT NULL auto_increment, + vendor_id varchar(6) DEFAULT '' NOT NULL, + -- rvid varchar(6) DEFAULT '' NOT NULL, + name varchar(255) DEFAULT '' NOT NULL, + phone varchar(24) DEFAULT '' NOT NULL, + location_id int(11) DEFAULT '0' NOT NULL, + -- lcid int(11) DEFAULT '0' NOT NULL, + email varchar(255) DEFAULT '' NOT NULL, + url varchar(255) DEFAULT '' NOT NULL, + tagline text, + logo_url varchar(255) DEFAULT '' NOT NULL, + upsell tinyint(4) DEFAULT '0', + start_date date, + end_date date, + PRIMARY KEY (id), + -- PRIMARY KEY (vid), + KEY name_idx (name), + KEY phone_idx (phone) +); +## }}} + +## Table structure for table 'style' {{{ +## +DROP TABLE IF EXISTS style; +CREATE TABLE style ( + id int(11) NOT NULL auto_increment, + -- sid int(11) NOT NULL auto_increment, + style varchar(42) DEFAULT '' NOT NULL, + abbrev varchar(42) DEFAULT '' NOT NULL, + PRIMARY KEY (id), + -- PRIMARY KEY (sid), + KEY style_idx (style) +); +## }}} + + + + +