@@ -5,6 +5,28 @@ import {
55 TouchChatValidator ,
66} from '../src/validation' ;
77import JSZip from 'jszip' ;
8+ import fs from 'fs' ;
9+ import os from 'os' ;
10+ import path from 'path' ;
11+ import AdmZip from 'adm-zip' ;
12+ import Database from 'better-sqlite3' ;
13+
14+ function createSqliteDbBuffer ( schemaSql : string , insertSql ?: string ) : Buffer {
15+ const dir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'aac-test-sqlite-' ) ) ;
16+ const dbPath = path . join ( dir , 'db.sqlite' ) ;
17+ const db = new Database ( dbPath ) ;
18+ try {
19+ db . exec ( schemaSql ) ;
20+ if ( insertSql ) {
21+ db . exec ( insertSql ) ;
22+ }
23+ } finally {
24+ db . close ( ) ;
25+ }
26+ const buffer = fs . readFileSync ( dbPath ) ;
27+ fs . rmSync ( dir , { recursive : true , force : true } ) ;
28+ return buffer ;
29+ }
830
931describe ( 'Validation Coverage Tests' , ( ) => {
1032 describe ( 'ObfValidator - Extended Coverage' , ( ) => {
@@ -591,9 +613,59 @@ describe('Validation Coverage Tests', () => {
591613 expect ( result . valid ) . toBe ( false ) ;
592614 expect ( result . format ) . toBe ( 'snap' ) ;
593615 } ) ;
616+
617+ it ( 'should validate sqlite-based Snap files' , async ( ) => {
618+ const sqliteBuffer = createSqliteDbBuffer ( `
619+ CREATE TABLE Page (Id INTEGER PRIMARY KEY, UniqueId TEXT, Name TEXT, Title TEXT);
620+ CREATE TABLE Button (Id INTEGER PRIMARY KEY, Label TEXT, Message TEXT);
621+ CREATE TABLE ElementReference (Id INTEGER PRIMARY KEY, PageId INTEGER);
622+ CREATE TABLE ElementPlacement (Id INTEGER PRIMARY KEY, ElementReferenceId INTEGER);
623+ CREATE TABLE PageSetProperties (Id INTEGER PRIMARY KEY, Name TEXT);
624+ ` ) ;
625+
626+ const result = await new SnapValidator ( ) . validate (
627+ sqliteBuffer ,
628+ 'test.sps' ,
629+ sqliteBuffer . length
630+ ) ;
631+
632+ expect ( result . valid ) . toBe ( true ) ;
633+ expect ( result . format ) . toBe ( 'snap' ) ;
634+ } ) ;
594635 } ) ;
595636
596637 describe ( 'TouchChatValidator - Extended Coverage' , ( ) => {
638+ it ( 'should validate TouchChat zip with sqlite db' , async ( ) => {
639+ const sqliteBuffer = createSqliteDbBuffer (
640+ `
641+ CREATE TABLE resources (id INTEGER PRIMARY KEY, name TEXT);
642+ CREATE TABLE pages (id INTEGER PRIMARY KEY, resource_id INTEGER);
643+ CREATE TABLE buttons (id INTEGER PRIMARY KEY, resource_id INTEGER);
644+ CREATE TABLE button_boxes (id INTEGER PRIMARY KEY);
645+ CREATE TABLE button_box_cells (id INTEGER PRIMARY KEY, resource_id INTEGER, button_box_id INTEGER);
646+ CREATE TABLE button_box_instances (id INTEGER PRIMARY KEY, page_id INTEGER, button_box_id INTEGER);
647+ ` ,
648+ `
649+ INSERT INTO resources (id, name) VALUES (1, 'Page 1');
650+ INSERT INTO pages (id, resource_id) VALUES (1, 1);
651+ INSERT INTO buttons (id, resource_id) VALUES (1, 1);
652+ INSERT INTO button_boxes (id) VALUES (1);
653+ INSERT INTO button_box_cells (id, resource_id, button_box_id) VALUES (1, 1, 1);
654+ INSERT INTO button_box_instances (id, page_id, button_box_id) VALUES (1, 1, 1);
655+ `
656+ ) ;
657+
658+ const zip = new AdmZip ( ) ;
659+ zip . addFile ( 'vocab.c4v' , sqliteBuffer ) ;
660+ const content = zip . toBuffer ( ) ;
661+
662+ const result = await new TouchChatValidator ( ) . validate ( content , 'test.ce' , content . length ) ;
663+
664+ expect ( result ) . toBeDefined ( ) ;
665+ expect ( result . format ) . toBe ( 'touchchat' ) ;
666+ expect ( result . valid ) . toBe ( true ) ;
667+ } ) ;
668+
597669 it ( 'should validate complete TouchChat structure' , async ( ) => {
598670 const completeTouchChat = `<?xml version="1.0" encoding="utf-8"?>
599671 <PageSet id="test" name="Test Pageset">
0 commit comments