1: %% 2: %% %CopyrightBegin% 3: %% 4: %% Copyright Ericsson AB 1997-2011. All Rights Reserved. 5: %% 6: %% The contents of this file are subject to the Erlang Public License, 7: %% Version 1.1, (the "License"); you may not use this file except in 8: %% compliance with the License. You should have received a copy of the 9: %% Erlang Public License along with this software. If not, it can be 10: %% retrieved online at http://www.erlang.org/. 11: %% 12: %% Software distributed under the License is distributed on an "AS IS" 13: %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 14: %% the License for the specific language governing rights and limitations 15: %% under the License. 16: %% 17: %% %CopyrightEnd% 18: %% 19: -module(win32reg_SUITE). 20: 21: -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, 22: init_per_group/2,end_per_group/2,long/1,evil_write/1]). 23: 24: -include_lib("test_server/include/test_server.hrl"). 25: 26: suite() -> [{ct_hooks,[ts_install_cth]}]. 27: 28: all() -> 29: [long, evil_write]. 30: 31: groups() -> 32: []. 33: 34: init_per_group(_GroupName, Config) -> 35: Config. 36: 37: end_per_group(_GroupName, Config) -> 38: Config. 39: 40: 41: init_per_suite(Config) when is_list(Config) -> 42: case os:type() of 43: {win32, _} -> 44: Config; 45: _ -> 46: {skip,"Doesn't run on UNIX."} 47: end. 48: end_per_suite(Config) when is_list(Config) -> 49: Config. 50: 51: long(doc) -> "Test long keys and entries (OTP-3446)."; 52: long(Config) when is_list(Config) -> 53: ?line Dog = test_server:timetrap(test_server:seconds(10)), 54: 55: ?line LongKey = "software\\" ++ 56: lists:flatten(lists:duplicate(10, "..\\software\\")) ++ 57: "Ericsson\\Erlang", 58: ?line {ok,Reg} = win32reg:open([read,write]), 59: ?line ok = win32reg:change_key(Reg, "\\hklm"), 60: ?line ok = win32reg:change_key(Reg, LongKey), 61: ?line {ok,ErlangKey} = win32reg:current_key(Reg), 62: io:format("Erlang key: ~s", [ErlangKey]), 63: 64: %% Write a long value and read it back. 65: ?line TestKey = "test_key", 66: ?line LongValue = lists:concat(["This is a long value generated by the test case ",?MODULE,":long/1. "|lists:duplicate(128, "a")]), 67: ?line ok = win32reg:set_value(Reg, TestKey, LongValue), 68: ?line {ok,LongValue} = win32reg:value(Reg, TestKey), 69: 70: %% Done. 71: 72: ?line ok = win32reg:close(Reg), 73: ?line test_server:timetrap_cancel(Dog), 74: ok. 75: 76: evil_write(Config) when is_list(Config) -> 77: ?line Dog = test_server:timetrap(test_server:seconds(10)), 78: 79: ?line Key = "Software\\Ericsson\\Erlang", 80: ?line {ok,Reg} = win32reg:open([read,write]), 81: ?line ok = win32reg:change_key(Reg, "\\hklm"), 82: ?line ok = win32reg:change_key(Reg, Key), 83: ?line {ok,ErlangKey} = win32reg:current_key(Reg), 84: io:format("Erlang key: ~s", [ErlangKey]), 85: 86: %% Write keys with different length and read it back. 87: ?line TestKey = "test_key " ++ lists:duplicate(128, $a), 88: evil_write_1(Reg, TestKey), 89: 90: %% Done. 91: ?line ok = win32reg:close(Reg), 92: ?line test_server:timetrap_cancel(Dog), 93: ok. 94: 95: evil_write_1(Reg, [_|[_|_]=Key]=Key0) -> 96: ?line io:format("Key = ~p\n", [Key0]), 97: ?line ok = win32reg:set_value(Reg, Key0, "A good value for me"), 98: ?line {ok,_Val} = win32reg:value(Reg, Key0), 99: ?line ok = win32reg:delete_value(Reg, Key0), 100: evil_write_1(Reg, Key); 101: evil_write_1(_, [_]) -> ok.