/* * Copyright (C) 2015-2017 PÂRIS Quentin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ package org.phoenicis.win32.registry; import org.junit.Test; import static org.junit.Assert.assertEquals; public class RegistryWriterTest { @Test public void testGenerateRegFile() throws Exception { final String baseLine = "WINE REGISTRY Version 2\n" + ";; Generated by Phoenicis\n" + "\n" + "[A]\n" + "\n" + "[A\\B]\n" + "\n" + "[A\\C]\n" + "\"D\"=hex:128,129,130\n" + "\"E\"=dword:10\n" + "\"F\"=str(2):\"Content\"\n" + "\"G\"=str(7):\"Content2\"\n" + "\"G\"=\"Content3\"\n"; final RegistryWriter registryWriter = new RegistryWriter(); RegistryKey testNodeA = new RegistryKey("A"); RegistryKey testNodeB = new RegistryKey("B"); RegistryKey testNodeC = new RegistryKey("C"); RegistryValue<BinaryValueType> testNodeD = new RegistryValue<>("D", new BinaryValueType(new byte[] { 0, 1, 2 })); RegistryValue<DwordValueType> testNodeE = new RegistryValue<>("E", new DwordValueType(10L)); RegistryValue<ExpandableValueType> testNodeF = new RegistryValue<>("F", new ExpandableValueType("Content")); RegistryValue<MultiStringValueType> testNodeG = new RegistryValue<>("G", new MultiStringValueType("Content2")); RegistryValue<StringValueType> testNodeH = new RegistryValue<>("G", new StringValueType("Content3")); testNodeA.addChild(testNodeB); testNodeA.addChild(testNodeC); testNodeC.addChildren(testNodeD, testNodeE, testNodeF, testNodeG, testNodeH); assertEquals(baseLine, registryWriter.generateRegFileContent(testNodeA)); } @Test public void testGenerateRegFileRemoveAValue() { final RegistryWriter registryWriter = new RegistryWriter(); AbstractRegistryNode testRemoveNode = new RegistryKey("HKEY_CURRENT_USER").addDeepChildren("test1", "test2", "test3"); ((RegistryKey) testRemoveNode).addChild(new RegistryValue<>("test4", new RemoveValueType())); assertEquals( "WINE REGISTRY Version 2\n" + ";; Generated by Phoenicis\n" + "\n" + "[HKEY_CURRENT_USER\\test1\\test2\\test3]\n" + "\"test4\"=-\n", registryWriter.generateRegFileContent(testRemoveNode)); } }