|
| 1 | +exports.test = function(sql, assert) { |
| 2 | + // Test 1: Create a database, Register single function, close database, repeat 1000 times |
| 3 | + for (var i = 1; i <= 1000; i++) |
| 4 | + { |
| 5 | + let db = new sql.Database(); |
| 6 | + function add() {return i;} |
| 7 | + try |
| 8 | + { |
| 9 | + db.create_function("TestFunction"+i, add) |
| 10 | + }catch(e) |
| 11 | + { |
| 12 | + assert.ok(false,"Test 1: Recreate database "+i+"th times and register function failed with exception:"+e); |
| 13 | + break; |
| 14 | + } |
| 15 | + var result = db.exec("SELECT TestFunction"+i+"()"); |
| 16 | + var result_str = result[0]["values"][0][0]; |
| 17 | + assert.equal(result_str, i, "Test 1: Recreate database "+i+"th times and register function"); |
| 18 | + db.close(); |
| 19 | + } |
| 20 | + |
| 21 | + // Test 2: Create a database, Register same function 1000 times, close database, repeat |
| 22 | + { |
| 23 | + let db = new sql.Database(); |
| 24 | + for (var i = 1; i <= 1000; i++) |
| 25 | + { |
| 26 | + function add() {return i;} |
| 27 | + try |
| 28 | + { |
| 29 | + db.create_function("TestFunction", add); |
| 30 | + }catch(e) |
| 31 | + { |
| 32 | + assert.ok(false,"Test 2: Reregister function "+i+"th times failed with exception:"+e); |
| 33 | + break; |
| 34 | + } |
| 35 | + var result = db.exec("SELECT TestFunction()"); |
| 36 | + var result_str = result[0]["values"][0][0]; |
| 37 | + assert.equal(result_str, i, "Test 2: Reregister function "+i+"th times"); |
| 38 | + } |
| 39 | + db.close(); |
| 40 | + } |
| 41 | +}; |
| 42 | + |
| 43 | + |
| 44 | +if (module == require.main) { |
| 45 | + const target_file = process.argv[2]; |
| 46 | + const sql_loader = require('./load_sql_lib'); |
| 47 | + sql_loader(target_file).then((sql)=>{ |
| 48 | + require('test').run({ |
| 49 | + 'test functions recreeate': function(assert){ |
| 50 | + exports.test(sql, assert); |
| 51 | + } |
| 52 | + }); |
| 53 | + }) |
| 54 | + .catch((e)=>{ |
| 55 | + console.error(e); |
| 56 | + assert.fail(e); |
| 57 | + }); |
| 58 | +} |
0 commit comments