public void TestDefaultSetting() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.PostProcess = Parameter.PostProcesses.None; ExecConvert(setting, ""); }
/* ----------------------------------------------------------------- */ /// /// SetupUserSetting /// /// <summary> /// プログラムに指定された引数等を用いて、UserSetting オブジェクトを /// 初期化します。 /// </summary> /// /* ----------------------------------------------------------------- */ private static void SetupUserSetting(UserSetting setting, string[] args) { var cmdline = new CubePdf.Settings.CommandLine(args); var docname = cmdline.Options.ContainsKey("DocumentName") ? cmdline.Options["DocumentName"] : ""; bool is_config = false; try { if (docname.Length > 0 && Path.GetExtension(docname) == setting.Extension && File.Exists(docname)) is_config = true; } catch (Exception err) { // docname に Windows のファイル名に使用できない記号が含まれる // 場合に例外が送出されるので、その対策。 Trace.TraceError(err.ToString()); is_config = false; } if (is_config) setting.Load(docname); else { setting.Load(); var filename = DocumentName.CreateFileName(docname); if (filename != null) { string ext = Parameter.Extension((Parameter.FileTypes)setting.FileType); filename = Path.ChangeExtension(filename, ext); string dir = (setting.OutputPath.Length == 0 || Directory.Exists(setting.OutputPath)) ? setting.OutputPath : Path.GetDirectoryName(setting.OutputPath); setting.OutputPath = dir + '\\' + filename; } } setting.InputPath = cmdline.Options.ContainsKey("InputFile") ? cmdline.Options["InputFile"] : ""; setting.DeleteOnClose = cmdline.Options.ContainsKey("DeleteOnClose"); }
public void TestDocument() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; setting.PostProcess = Parameter.PostProcesses.None; setting.Document.Title = "テスト"; setting.Document.Author = "株式会社キューブ・ソフト"; setting.Document.Subtitle = "Document property test. 文書プロパティのテスト"; setting.Document.Keyword = "文書プロパティ, テスト, test, documents, CubePDF"; ExecConvert(setting, "-document"); }
public void TestEmbedFont() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; setting.PostProcess = Parameter.PostProcesses.None; setting.EmbedFont = true; ExecConvert(setting, "-embed"); setting.EmbedFont = false; ExecConvert(setting, "-noembed"); }
public void TestSaveEmptyString() { using (var saver = new UserSettingSaver()) { string dummy = "dummy"; var test = new UserSetting(false); test.InputPath = dummy; test.OutputPath = dummy; test.UserProgram = dummy; test.UserArguments = dummy; Assert.IsTrue(test.Save(), "Save from registry"); Assert.IsTrue(test.Load(), "Load from registry"); Assert.AreEqual(dummy, test.OutputPath, "LastAccess"); Assert.AreEqual(dummy, test.InputPath, "LastInputAccess"); Assert.AreEqual(dummy, test.UserProgram, "UserProgram"); Assert.AreEqual(dummy, test.UserArguments, "UserArguments"); string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); test.InputPath = string.Empty; test.OutputPath = string.Empty; test.UserProgram = string.Empty; test.UserArguments = string.Empty; Assert.IsTrue(test.Save(), "Save from registry (second)"); Assert.IsTrue(test.Load(), "Load from registry (second)"); Assert.AreEqual(desktop, test.OutputPath, "LastAccess"); // empty ではない Assert.AreEqual(desktop, test.InputPath, "LastInputAccess"); // empty ではない Assert.AreEqual(string.Empty, test.UserProgram, "UserProgram"); Assert.AreEqual(string.Empty, test.UserArguments, "UserArguments"); } }
public void TestSaveNotFoundPath() { using (var saver = new UserSettingSaver()) { var test = new UserSetting(false); Assert.IsTrue(test.Load(), "Load from registry"); string not_found = @"C:\404_notfound\foo\bar\bas\foo.txt"; test.OutputPath = not_found; test.InputPath = not_found; Assert.IsTrue(test.Save(), "Save to registry"); Assert.IsTrue(test.Load(), "Load from registry (second)"); Assert.AreEqual(not_found, test.OutputPath, "LastAccess"); Assert.AreEqual(not_found, test.InputPath, "LastInputAccess"); } }
public void TestPdfVersion() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; setting.PostProcess = Parameter.PostProcesses.None; setting.PDFVersion = Parameter.PdfVersions.Ver1_2; ExecConvert(setting, '-' + setting.PDFVersion.ToString()); setting.PDFVersion = Parameter.PdfVersions.VerPDFA; ExecConvert(setting, '-' + setting.PDFVersion.ToString()); setting.PDFVersion = Parameter.PdfVersions.VerPDFX; ExecConvert(setting, '-' + setting.PDFVersion.ToString()); }
public void TestRegisterUpdateChecker() { using (var saver = new UserSettingSaver()) { var test = new UserSetting(false); Assert.IsTrue(test.Load(), "Load from registry"); test.CheckUpdate = true; Assert.IsTrue(test.Save(), "Save to registry (CheckUpdate = true)"); { var subkey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", false); Assert.IsTrue(subkey != null, @"HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); Assert.IsTrue(subkey.GetValue("cubepdf-checker") != null); } test.CheckUpdate = false; Assert.IsTrue(test.Save(), "Save to registry (CheckUpdate = false)"); { var subkey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", false); Assert.IsTrue(subkey != null, @"HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); Assert.IsTrue(subkey.GetValue("cubepdf-checker") == null); } } }
public void TestMerge() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; setting.PostProcess = Parameter.PostProcesses.None; ExecConvert(setting, "-head"); setting.ExistedFile = Parameter.ExistedFiles.MergeHead; ExecConvert(setting, "-head"); setting.ExistedFile = Parameter.ExistedFiles.Overwrite; ExecConvert(setting, "-tail"); setting.ExistedFile = Parameter.ExistedFiles.MergeTail; ExecConvert(setting, "-tail"); }
public void TestPassword() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; setting.PostProcess = Parameter.PostProcesses.None; setting.Password = "******"; setting.Permission.Password = "******"; ExecConvert(setting, "-password"); // パスワード付きの PDF ファイルに結合するテスト setting.ExistedFile = Parameter.ExistedFiles.MergeHead; ExecConvert(setting, "-password"); }
public void TestImageFilter() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; setting.ImageFilter = Parameter.ImageFilters.DCTEncode; setting.PostProcess = Parameter.PostProcesses.None; ExecConvert(setting, "-filter"); }
public void TestGrayscale() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.Grayscale = true; setting.PostProcess = Parameter.PostProcesses.None; setting.FileType = Parameter.FileTypes.PDF; ExecConvert(setting, "-grayscale"); setting.FileType = Parameter.FileTypes.JPEG; ExecConvert(setting, "-grayscale"); }
public void TestFileType() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.PostProcess = Parameter.PostProcesses.None; foreach (Parameter.FileTypes type in Enum.GetValues(typeof(Parameter.FileTypes))) { setting.FileType = type; ExecConvert(setting, "-type"); } }
/* ----------------------------------------------------------------- */ /// /// LoadUserSetting /// /// <summary> /// レジストリからユーザ設定をロードします。 /// </summary> /// /* ----------------------------------------------------------------- */ private static void LoadUserSetting(UserSetting setting, CubePdf.Settings.CommandLine cmdline) { if (cmdline.Options.ContainsKey("Em")) { setting.Load(cmdline.Options["UserName"]); setting.EmergencyMode = true; setting.PostProcess = Parameter.PostProcesses.OpenFolder; } else setting.Load(); }
public void TestPermission() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; setting.PostProcess = Parameter.PostProcesses.None; setting.Permission.Password = "******"; setting.Permission.AllowCopy = false; setting.Permission.AllowFormInput = false; setting.Permission.AllowModify = false; setting.Permission.AllowPrint = false; ExecConvert(setting, "-deny"); setting.Permission.AllowCopy = true; setting.Permission.AllowFormInput = true; setting.Permission.AllowModify = true; setting.Permission.AllowPrint = true; ExecConvert(setting, "-allow"); }
public void TestLoadValue() { try { var load_from_constructor = new UserSetting(true); load_from_constructor = null; var load_from_method = new UserSetting(false); Assert.IsTrue(load_from_method.Load(), "Load from registry"); load_from_method = null; } catch (Exception err) { Assert.Fail(err.ToString()); } }
public void TestRename() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.ExistedFile = Parameter.ExistedFiles.Rename; setting.PostProcess = Parameter.PostProcesses.None; setting.FileType = Parameter.FileTypes.PDF; ExecConvert(setting, "-rename"); ExecConvert(setting, "-rename"); setting.FileType = Parameter.FileTypes.JPEG; ExecConvert(setting, "-rename"); ExecConvert(setting, "-rename"); }
public void TestSaveDefaultValue() { using (var saver = new UserSettingSaver()) { var default_value = new UserSetting(false); Assert.IsTrue(default_value.Save(), "Save to registry"); string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); var test = new UserSetting(false); Assert.IsTrue(test.Load(), "Load from registry"); // 各種デフォルト値のテスト Assert.AreEqual(desktop, test.OutputPath, "LastAccess"); Assert.AreEqual(desktop, test.InputPath, "LastInputAccess"); Assert.AreEqual("", test.UserProgram, "UserProgram"); Assert.AreEqual("%%FILE%%", test.UserArguments, "UserArguments"); Assert.AreEqual(Parameter.FileTypes.PDF, test.FileType, "FileType"); Assert.AreEqual(Parameter.PdfVersions.Ver1_7, test.PDFVersion, "PDFVersion"); Assert.AreEqual(Parameter.Resolutions.Resolution300, test.Resolution, "Resolution"); Assert.AreEqual(Parameter.Orientations.Auto, test.Orientation, "Orientation"); Assert.AreEqual(Parameter.ExistedFiles.Overwrite, test.ExistedFile, "ExistedFile"); Assert.AreEqual(Parameter.PostProcesses.Open, test.PostProcess, "PostProcess"); Assert.AreEqual(Parameter.ImageFilters.FlateEncode, test.ImageFilter, "ImageFilter"); Assert.AreEqual(Parameter.SaveSettings.None, test.SaveSetting, "SaveSetting"); Assert.IsTrue(test.EmbedFont, "EmbedFont"); // フォントの埋め込み Assert.IsFalse(test.Grayscale, "Grayscale"); // グレースケール Assert.IsFalse(test.WebOptimize, "WebOptimize"); // Web 表示用に最適化 Assert.IsTrue(test.CheckUpdate, "CheckUpdate"); // 起動時にアップデートを確認する Assert.IsFalse(test.AdvancedMode, "AdvancedMode"); // ポストプロセスでユーザ―プログラムを選択可能にする Assert.IsFalse(test.SelectInputFile, "SelectInputFile"); // 入力ファイル欄を表示 Assert.IsFalse(test.DeleteOnClose, "DeleteOnClose"); // 終了時に入力ファイルを消去(レジストリには項目なし) Assert.IsTrue(test.Visible, "Visible"); } }
public void TestResolution() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.JPEG; setting.PostProcess = Parameter.PostProcesses.None; setting.Resolution = Parameter.Resolutions.Resolution72; ExecConvert(setting, '-' + setting.Resolution.ToString()); setting.Resolution = Parameter.Resolutions.Resolution300; ExecConvert(setting, '-' + setting.Resolution.ToString()); }
public void TestSaveInvalidValue() { using (var saver = new UserSettingSaver()) { try { var subkey = Registry.CurrentUser.OpenSubKey(@"Software\CubeSoft\CubePDF\v2", true); Assert.IsTrue(subkey != null, @"HKCU\Software\CubeSoft\CubePDF\v2"); // コンボボックスの値 // NOTE: ImageFilter のみ GUI 上はチェックボックスである。 // また、SaveSetting の値は、1.0.0RC4 以降、GUI 上では使用されていない。 subkey.SetValue("FileType", 256); subkey.SetValue("PDFVersion", 1024); subkey.SetValue("Resolution", 5012); subkey.SetValue("Orientation", 12345); subkey.SetValue("ExistedFile", 8252); subkey.SetValue("PostProcess", 2958739); subkey.SetValue("DownSampling", 493798); subkey.SetValue("ImageFilter", 943724); subkey.SetValue("SaveSetting", 24); // チェックボックスの値(正常な値は、0 or 1) subkey.SetValue("EmbedFont", 5); subkey.SetValue("Grayscale", 8); subkey.SetValue("WebOptimize", 12); subkey.SetValue("CheckUpdate", 32); subkey.SetValue("AdvancedMode", 42); subkey.SetValue("SelectInputFile", 128); } catch (Exception err) { Assert.Fail(err.ToString()); } var test = new UserSetting(false); Assert.IsTrue(test.Load(), "Load from registry"); Assert.AreEqual(Parameter.FileTypes.PDF, test.FileType, "FileType"); Assert.AreEqual(Parameter.PdfVersions.Ver1_7, test.PDFVersion, "PDFVersion"); Assert.AreEqual(Parameter.Resolutions.Resolution300, test.Resolution, "Resolution"); Assert.AreEqual(Parameter.Orientations.Auto, test.Orientation, "Orientation"); Assert.AreEqual(Parameter.ExistedFiles.Overwrite, test.ExistedFile, "ExistedFile"); Assert.AreEqual(Parameter.PostProcesses.Open, test.PostProcess, "PostProcess"); Assert.AreEqual(Parameter.ImageFilters.FlateEncode, test.ImageFilter, "ImageFilter"); Assert.AreEqual(Parameter.SaveSettings.None, test.SaveSetting, "SaveSetting"); Assert.IsTrue(test.EmbedFont, "EmbedFont"); Assert.IsTrue(test.Grayscale, "Grayscale"); Assert.IsTrue(test.WebOptimize, "WebOptimize"); Assert.IsTrue(test.CheckUpdate, "CheckUpdate"); Assert.IsTrue(test.AdvancedMode, "AdvancedMode"); Assert.IsTrue(test.SelectInputFile, "SelectInputFile"); } }
public void TestWebOptimize() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; setting.PostProcess = Parameter.PostProcesses.None; setting.WebOptimize = true; ExecConvert(setting, "-webopt"); }
public void TestDeleteStringValue() { using (var saver = new UserSettingSaver()) { // 値をレジストリ操作で無理やり消す。 try { var subkey = Registry.CurrentUser.OpenSubKey(@"Software\CubeSoft\CubePDF\v2", true); Assert.IsTrue(subkey != null, @"HKCU\Software\CubeSoft\CubePDF\v2"); subkey.DeleteValue("LastAccess", false); subkey.DeleteValue("LastInputAccess", false); subkey.DeleteValue("UserProgram", false); subkey.DeleteValue("UserArguments", false); } catch (Exception err) { Assert.Fail(err.ToString()); } string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); var test = new UserSetting(false); Assert.IsTrue(test.Load(), "Load from registry (second)"); Assert.AreEqual(desktop, test.OutputPath, "LastAccess"); Assert.AreEqual(desktop, test.InputPath, "LastInputAccess"); Assert.AreEqual(string.Empty, test.UserProgram, "UserProgram"); Assert.AreEqual("%%FILE%%", test.UserArguments, "UserArguments"); } }
public void TestDownSampling() { var setting = new UserSetting(false); Assert.IsTrue(setting.Load(), "Load from registry"); setting.FileType = Parameter.FileTypes.PDF; foreach (Parameter.DownSamplings sampling in Enum.GetValues(typeof(Parameter.DownSamplings))) { setting.DownSampling = sampling; setting.PostProcess = Parameter.PostProcesses.None; ExecConvert(setting, '-' + sampling.ToString()); } }