-- ACL format checks
select ''::ace_uuid;
select 'a'::ace_uuid;
select 'q'::ace_uuid;
select 'a*'::ace_uuid;

select 'a/'::ace_uuid;
select 'a/hq'::ace_uuid;
select 'a/h'::ace_uuid;

select 'a/h/'::ace_uuid;

select 'a/h/='::ace_uuid;
select 'a/h/00000000-0000-0000-0000-000000000001='::ace_uuid;
select 'a/h/00000000-0000-0000-0000-000000000001=d,'::ace_uuid;
select 'a/h/00000000-0000-0000-0000-000000000001=dw'::ace_uuid;
select 'a/ihpc/00000000-0000-0000-0000-000000000001=wdddw'::ace_uuid;
select 'd/ihpc/00000000-0000-0000-0000-000000000001=wdddw'::ace_uuid;
select 'd/ihpc/a0000000-ffff-b000-c000-d00000000001=wdddw'::ace_uuid;
select 'a/ihpc/blah"=dw0'::ace_uuid;
select 'd/ihpc/a0000000-ffff-b000-c000-d000000000010000=wdddw'::ace_uuid;

-- check access
select acl_check_access('{d//00000000-0000-0000-0000-000000000001=w,d//00000000-0000-0000-0000-000000000002=s,a//00000000-0000-0000-0000-000000000002=sdw,a//00000000-0000-0000-0000-000000000003=0}'::ace_uuid[], 'sd0', '{00000000-0000-0000-0000-000000000003, 00000000-0000-0000-0000-000000000002}'::uuid[], false);

-- inherit only
select acl_check_access('{d//00000000-0000-0000-0000-000000000001=w,d/i/00000000-0000-0000-0000-000000000002=s,a//00000000-0000-0000-0000-000000000002=sdw,a//00000000-0000-0000-0000-000000000003=0}'::ace_uuid[], 'sd0', '{00000000-0000-0000-0000-000000000003, 00000000-0000-0000-0000-000000000002}'::uuid[], false);

-- merge
select acl_merge(null::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], true, false);
select acl_merge(null::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], true, true);
select acl_merge(null::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, false);
select acl_merge(null::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, true);

-- inheritance

-- container

-- no flags -> not inherited
select acl_merge('{a//00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], true, false);

-- inherit only -> not inherited
select acl_merge('{a/i/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], true, false);

-- object inherit -> inherit only + object inherit
select acl_merge('{a/o/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], true, false);

-- object inherit + no propagate inherit -> no inheritance
select acl_merge('{a/op/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], true, false);

--container inherit -> container inherit
select acl_merge('{a/c/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], true, false);

-- container inherit + no propagate inherit -> no flags
select acl_merge('{a/cp/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], true, false);

-- container inherit + object inherit -> container inherit + object inherit + inherit only
select acl_merge('{a/co/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], true, false);

-- container inherit + object inherit + no propagate inherit -> no flags
select acl_merge('{a/cop/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], true, false);

-- object

-- no flags -> not inherited
select acl_merge('{a//00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, false);

-- inherit only -> not inherited
select acl_merge('{a/i/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, false);

-- object inherit -> no flags
select acl_merge('{a/o/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, false);

-- object inherit + no propagate inherit -> no flags
select acl_merge('{a/op/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, false);

--container inherit -> not inherited
select acl_merge('{a/c/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, false);

-- container inherit + no propagate inherit -> not inherited
select acl_merge('{a/cp/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, false);

-- container inherit + object inherit -> no flags
select acl_merge('{a/co/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, false);

-- container inherit + object inherit + no propagate inherit -> no flags
select acl_merge('{a/cop/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, false);

-- skip inherited
select acl_merge('{a/h/00000000-0000-0000-0000-000000000001=d}'::ace_uuid[], '{a//00000000-0000-0000-0000-000000000000=0,d//00000000-0000-0000-0000-000000000000=1,a//00000000-0000-0000-0000-000000000000=23,d//00000000-0000-0000-0000-000000000000=4}'::ace_uuid[], false, false);
