-
Notifications
You must be signed in to change notification settings - Fork 43
/
key.js
73 lines (58 loc) · 2.47 KB
/
key.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* global describe, it */
'use strict';
require('./test_helper');
var assert = require('assert'),
windef = require('../index').windef,
Key = require('../index').Key;
describe('Key Open Tests', () => {
it('Should create a key given a subkey', () => {
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
assert(key.handle !== null && key.handle !== undefined);
key.close();
});
it('Should open a subkey provided a previously opened key', () => {
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '', windef.KEY_ACCESS.KEY_ALL_ACCESS);
var key2 = key.openSubKey('.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
assert(key2.handle !== null && key2.handle !== undefined);
key.close();
key2.close();
});
it('Should properly close', () => {
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
key.close();
// ensure that the key is actually closed by trying to open a subkey
// which should fail
assert.throws(() => {
key.openSubKey('OpenWithList', windef.KEY_ACCESS.KEY_ALL_ACCESS);
});
});
});
describe('Create Key Tests', function () {
it('Should create a new key and Delete it', () => {
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
assert(key.handle !== undefined);
assert(key.handle !== null);
var createdKey = key.createSubKey('\test_key_name', windef.KEY_ACCESS.KEY_ALL_ACCESS);
assert(createdKey.handle !== undefined);
assert(createdKey.handle !== null);
assert(createdKey.path === '\test_key_name');
createdKey.deleteKey();
assert.throws(() => {
key.openSubKey('\test_key_name', windef.KEY_ACCESS.KEY_ALL_ACCESS);
}, (err) => {
assert(err.indexOf('ERROR_FILE_NOT_FOUND') > -1);
return true;
});
key.close();
});
});
describe('Set / Query Value Tests', function () {
it('Should set and read REG_SZ Value', () => {
var key = new Key(windef.HKEY.HKEY_CLASSES_ROOT, '.txt', windef.KEY_ACCESS.KEY_ALL_ACCESS);
assert(key.handle !== null && key.handle !== undefined);
key.setValue('test_value_name', windef.REG_VALUE_TYPE.REG_SZ, 'test_value');
var value = key.getValue('test_value_name');
assert.equal(value, 'test_value');
key.close();
});
});