Index: openacs-4/packages/acs-kernel/sql/test/rel-constraints-test.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/test/rel-constraints-test.sql,v diff -u -r1.3 -r1.4 --- openacs-4/packages/acs-kernel/sql/test/rel-constraints-test.sql 30 Apr 2001 01:34:02 -0000 1.3 +++ openacs-4/packages/acs-kernel/sql/test/rel-constraints-test.sql 30 Mar 2013 19:32:40 -0000 1.4 @@ -19,12 +19,12 @@ uname varchar(100) ); -create function rel_constraint_dump_views() returns integer as ' +CREATE OR REPLACE FUNCTION rel_constraint_dump_views() RETURNS integer AS $$ r record; str varchar; -begin +BEGIN - raise NOTICE ''Contents of view ''rel_constraints_violated_one'':''; + raise NOTICE 'Contents of view 'rel_constraints_violated_one':'; for r in select * from rel_constraints_violated_one LOOP @@ -33,11 +33,11 @@ rpad(acs_object__name(r.container_id), 20) || rpad(acs_object__name(r.party_id), 20); - raise NOTICE ''%'', str; + raise NOTICE '%', str; end LOOP; - raise NOTICE ''Contents of view ''rel_constraints_violated_two'':''; + raise NOTICE 'Contents of view 'rel_constraints_violated_two':'; for r in select * from rel_constraints_violated_two LOOP @@ -46,32 +46,41 @@ rpad(acs_object__name(r.container_id), 20) || rpad(acs_object__name(r.party_id), 20); - raise NOTICE ''%'', str; + raise NOTICE '%', str; end loop; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -create function rel_constraint_test_check (integer, boolean) -returns integer as ' -declare - rel_id alias for $1; - expect_violation_p alias for $2; + + +-- added +select define_function_args('rel_constraint_test_check','rel_id,expect_violation_p'); + +-- +-- procedure rel_constraint_test_check/2 +-- +CREATE OR REPLACE FUNCTION rel_constraint_test_check( + rel_id integer, + expect_violation_p boolean +) RETURNS integer AS $$ +DECLARE v_violation_msg varchar(4000); v_violation_p boolean; v_object_id_one integer; v_object_id_two integer; v_rel_type acs_rels.rel_type%TYPE; str varchar; -begin +BEGIN - v_violation_p := ''f''; + v_violation_p := 'f'; v_violation_msg := rel_constraint__violation(rel_id); if v_violation_msg is not null then - v_violation_p := ''t''; + v_violation_p := 't'; end if; if v_violation_p != expect_violation_p then @@ -81,36 +90,44 @@ from acs_rels where rel_id = rel_constraint_test_check.rel_id; - str := ''Relation '' || acs_object_name(rel_id) || - '' ('' || rel_id || '')'' || - '' failed (violation_p = '' || v_violation_p || ''). '' || - ''Rel info: type = '' || v_rel_type || - '', object one = '' || + str := 'Relation ' || acs_object_name(rel_id) || + ' (' || rel_id || ')' || + ' failed (violation_p = ' || v_violation_p || '). ' || + 'Rel info: type = ' || v_rel_type || + ', object one = ' || acs_object__name(v_object_id_one) || - '' ('' || v_object_id_one || '')'' || - '', object two = '' || + ' (' || v_object_id_one || ')' || + ', object two = ' || acs_object__name(v_object_id_two) || - '' ('' || v_object_id_two || '').''; + ' (' || v_object_id_two || ').'; - PERFORM acs_log__error(''rel_constraint_test_check'', str); + PERFORM acs_log__error('rel_constraint_test_check', str); - raise NOTICE ''%'', str; + raise NOTICE '%', str; - raise NOTICE ''Violation Message:''; - raise NOTICE ''%'', v_violation_msg; + raise NOTICE 'Violation Message:'; + raise NOTICE '%', v_violation_msg; end if; return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; -- creates blah_member_rel and yippe_member_rel relationships \i rel-segments-test-types-create.sql -create function test_rel_constraints() returns integer as ' -declare + + +-- +-- procedure test_rel_constraints/0 +-- +CREATE OR REPLACE FUNCTION test_rel_constraints( + +) RETURNS integer AS $$ +DECLARE A integer; B integer; C integer; @@ -139,54 +156,54 @@ r record; -begin +BEGIN -- Create the test groups. - A := acs_group__new(''A''); - B := acs_group__new(''B''); - C := acs_group__new(''C''); - D := acs_group__new(''D''); - E := acs_group__new(''E''); - F := acs_group__new(''F''); - G := acs_group__new(''G''); + A := acs_group__new('A'); + B := acs_group__new('B'); + C := acs_group__new('C'); + D := acs_group__new('D'); + E := acs_group__new('E'); + F := acs_group__new('F'); + G := acs_group__new('G'); - insert into groups_test_groups values (A,1,''A''); - insert into groups_test_groups values (B,2,''B''); - insert into groups_test_groups values (C,3,''C''); - insert into groups_test_groups values (D,4,''D''); - insert into groups_test_groups values (E,5,''E''); - insert into groups_test_groups values (F,6,''F''); - insert into groups_test_groups values (G,7,''G''); + insert into groups_test_groups values (A,1,'A'); + insert into groups_test_groups values (B,2,'B'); + insert into groups_test_groups values (C,3,'C'); + insert into groups_test_groups values (D,4,'D'); + insert into groups_test_groups values (E,5,'E'); + insert into groups_test_groups values (F,6,'F'); + insert into groups_test_groups values (G,7,'G'); -- Create the test members. - joe := acs_user__new(''joe@asdf.com'',''Joe'', - ''Smith'',''assword'',''p''); - jane := acs_user__new(''jane@asdf.com'',''Jane'', - ''Smith'',''assword'',''p''); - bob := acs_user__new(''bob@asdf.com'',''Bob'', - ''Smith'',''assword'',''p''); - betty := acs_user__new(''betty@asdf.com'',''Betty'', - ''Smith'',''assword'',''p''); - jack := acs_user__new(''jack@asdf.com'',''Jack'', - ''Smith'',''assword'',''p''); - jill := acs_user__new(''jill@asdf.com'',''Jill'', - ''Smith'',''assword'',''p''); - sven := acs_user__new(''sven@asdf.com'',''Sven'', - ''Smith'',''assword'',''p''); - stacy := acs_user__new(''stacy@asdf.com'',''Stacy'', - ''Smith'',''assword'',''p''); + joe := acs_user__new('joe@asdf.com','Joe', + 'Smith','assword','p'); + jane := acs_user__new('jane@asdf.com','Jane', + 'Smith','assword','p'); + bob := acs_user__new('bob@asdf.com','Bob', + 'Smith','assword','p'); + betty := acs_user__new('betty@asdf.com','Betty', + 'Smith','assword','p'); + jack := acs_user__new('jack@asdf.com','Jack', + 'Smith','assword','p'); + jill := acs_user__new('jill@asdf.com','Jill', + 'Smith','assword','p'); + sven := acs_user__new('sven@asdf.com','Sven', + 'Smith','assword','p'); + stacy := acs_user__new('stacy@asdf.com','Stacy', + 'Smith','assword','p'); - insert into groups_test_users values (joe,1,''joe''); - insert into groups_test_users values (jane,2,''jane''); - insert into groups_test_users values (bob,3,''bob''); - insert into groups_test_users values (betty,4,''betty''); - insert into groups_test_users values (jack,5,''jack''); - insert into groups_test_users values (jill,6,''jill''); - insert into groups_test_users values (sven,7,''sven''); - insert into groups_test_users values (stacy,8,''stacy''); + insert into groups_test_users values (joe,1,'joe'); + insert into groups_test_users values (jane,2,'jane'); + insert into groups_test_users values (bob,3,'bob'); + insert into groups_test_users values (betty,4,'betty'); + insert into groups_test_users values (jack,5,'jack'); + insert into groups_test_users values (jill,6,'jill'); + insert into groups_test_users values (sven,7,'sven'); + insert into groups_test_users values (stacy,8,'stacy'); -- Make a couple of compositions. - reg_users := acs__magic_object_id(''registered_users''); + reg_users := acs__magic_object_id('registered_users'); rel_id := composition_rel__new(A, B); rel_id := composition_rel__new(A, C); @@ -204,14 +221,14 @@ side_two_constraint := rel_constraint__new( null, - ''rel_constraint'', - ''Yippe: side 2 must be a blah of A'', + 'rel_constraint', + 'Yippe: side 2 must be a blah of A', rel_segment__get_or_new(reg_users, - ''yippe_member_rel'', + 'yippe_member_rel', null), - ''two'', + 'two', rel_segment__get_or_new(A, - ''blah_member_rel'', + 'blah_member_rel', null), null, null, @@ -222,14 +239,14 @@ side_one_constraint := rel_constraint__new( null, - ''rel_constraint'', - ''Yippe: side 1 must be a component of E'', + 'rel_constraint', + 'Yippe: side 1 must be a component of E', rel_segment__get_or_new(reg_users, - ''yippe_member_rel'', + 'yippe_member_rel', null), - ''one'', + 'one', rel_segment__get_or_new(E, - ''composition_rel'', + 'composition_rel', null), null, null, @@ -248,42 +265,42 @@ -- joe is a blah of A, and F is component of E, so its legal to make joe -- a yippe of F. - rel_id := blah_member_rel__new(null, ''blah_member_rel'', A, joe); + rel_id := blah_member_rel__new(null, 'blah_member_rel', A, joe); - PERFORM rel_constraint_test_check(rel_id, ''f''); + PERFORM rel_constraint_test_check(rel_id, 'f'); - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', F, joe); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', F, joe); - PERFORM rel_constraint_test_check(rel_id, ''f''); + PERFORM rel_constraint_test_check(rel_id, 'f'); -- do constraints respect group hierarchy? If so, this will be legal: - rel_id := blah_member_rel__new(null, ''blah_member_rel'', B, jane); + rel_id := blah_member_rel__new(null, 'blah_member_rel', B, jane); - PERFORM rel_constraint_test_check(rel_id, ''f''); + PERFORM rel_constraint_test_check(rel_id, 'f'); - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', F, jane); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', F, jane); - PERFORM rel_constraint_test_check(rel_id, ''f''); + PERFORM rel_constraint_test_check(rel_id, 'f'); -- ILLEGAL MEMBERSHIPS: -- G is not a component of F, therefore no one can be a yippe of G -- This should violated 2 constraints (object one and object two are both -- invalid). - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', G, bob); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', G, bob); - PERFORM rel_constraint_test_check(rel_id, ''t''); + PERFORM rel_constraint_test_check(rel_id, 't'); -- betty is not a blah of A, therefore she cannot be a yippe of F. - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', F, betty); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', F, betty); - PERFORM rel_constraint_test_check(rel_id, ''t''); + PERFORM rel_constraint_test_check(rel_id, 't'); -- make sven be a regular member of A. Sven cannot be a yippe of F. rel_id := membership_rel__new(A, sven); - rel_id := yippe_member_rel__new(null, ''yippie_member_rel'', F, sven); + rel_id := yippe_member_rel__new(null, 'yippie_member_rel', F, sven); - PERFORM rel_constraint_test_check(rel_id, ''t''); + PERFORM rel_constraint_test_check(rel_id, 't'); -- TEST THE VIEWS (there should be 4 violated constraints, -- 1 side one violation and 3 side two violations. @@ -292,7 +309,7 @@ from rel_constraints_violated_one; if v_count != 1 then - raise NOTICE ''rel_constraints_violated_one should have 1 row. Found % rows.'', + raise NOTICE 'rel_constraints_violated_one should have 1 row. Found % rows.', v_count; PERFORM rel_constraint_dump_views(); end if; @@ -301,7 +318,7 @@ from rel_constraints_violated_two; if v_count != 3 then - raise NOTICE ''rel_constraints_violated_two should have 2 rows. Found % rows.'', + raise NOTICE 'rel_constraints_violated_two should have 2 rows. Found % rows.', v_count; PERFORM rel_constraint_dump_views(); end if; @@ -321,9 +338,9 @@ end loop; -- Remove the test segments. - PERFORM rel_segment__delete(rel_segment__get(A,''blah_member_rel'')); - PERFORM rel_segment__delete(rel_segment__get(E,''composition_rel'')); - PERFORM rel_segment__delete(rel_segment__get(reg_users,''yippe_member_rel'')); + PERFORM rel_segment__delete(rel_segment__get(A,'blah_member_rel')); + PERFORM rel_segment__delete(rel_segment__get(E,'composition_rel')); + PERFORM rel_segment__delete(rel_segment__get(reg_users,'yippe_member_rel')); -- Remove the test groups. PERFORM acs_group__delete(G); @@ -346,7 +363,8 @@ return null; -end;' language 'plpgsql'; +END; +$$ LANGUAGE plpgsql; select test_rel_constraints();