1 // ================================================================================================
3 // FormUtilsのテストクラスソース。</summary>
5 // <copyright file="FormUtilsTest.cs" company="honeplusのメモ帳">
6 // Copyright (C) 2012 Honeplus. All rights reserved.</copyright>
9 // ================================================================================================
11 namespace Honememo.Wptscs.Utilities
14 using System.Windows.Forms;
15 using Honememo.Wptscs.Utilities;
16 using NUnit.Framework;
19 /// FormUtilsのテストクラスです。
22 /// その性質上、画面周りのメソッドならびに設定ファイル関連のメソッドについてはテストケースが作成できていない。
23 /// これらのメソッドに手を入れる際は注意すること。
26 public class FormUtilsTest
31 /// ReplaceInvalidFileNameCharsメソッドテストケース。
34 public void TestApplicationName()
36 // ※ バージョンが変わるごとにバージョン表記の部分を書き換えるのは面倒なので置換
38 "Wikipedia 翻訳支援ツール VerX.XX",
39 new System.Text.RegularExpressions.Regex("Ver[0-9]+\\.[0-9]+").Replace(FormUtils.ApplicationName(), "VerX.XX"));
43 /// ReplaceInvalidFileNameCharsメソッドテストケース。
46 public void TestReplaceInvalidFileNameChars()
48 Assert.AreEqual("C__test_test.doc", FormUtils.ReplaceInvalidFileNameChars("C:\\test\\test.doc"));
49 Assert.AreEqual("_home_test_test.doc", FormUtils.ReplaceInvalidFileNameChars("/home/test/test.doc"));
50 Assert.AreEqual("______", FormUtils.ReplaceInvalidFileNameChars("*?\"<>|"));
52 // 一見普通のファイル名に見えるが、 由来の半角スペース (u00a0) が含まれており問題を起こす
53 // 通常の半角スペース (u0020) に変換する
54 Assert.AreEqual("Fuji (Spacecraft).xml", FormUtils.ReplaceInvalidFileNameChars("Fuji (Spacecraft).xml"));
59 #region null値許容メソッドテストケース
62 /// ToStringメソッドテストケース。
65 public void TestToString()
68 Assert.IsNull(FormUtils.ToString(null, null));
69 Assert.IsNull(FormUtils.ToString(new DummyCell(), null));
70 Assert.AreEqual("null", FormUtils.ToString(new DummyCell(), "null"));
71 Assert.AreEqual("not null", FormUtils.ToString(new DummyCell { Value = "not null" }, "null"));
72 Assert.AreNotEqual("null", FormUtils.ToString(new DummyCell { Value = new object() }, "null"));
75 Assert.AreEqual(String.Empty, FormUtils.ToString(null));
76 Assert.AreEqual(String.Empty, FormUtils.ToString(new DummyCell()));
77 Assert.AreEqual("not null", FormUtils.ToString(new DummyCell { Value = "not null" }));
78 Assert.IsNotEmpty(FormUtils.ToString(new DummyCell { Value = new object() }));
86 /// DataGridViewCellテスト用のモッククラスです。
88 public class DummyCell : DataGridViewCell