public void ReadTagTest() { // Arrange double gammaUcr = 2.4, gammaBg = -2.2; string languageCode = "en"; string countryCode = "US"; string expectedText = "read-tag"; using (var ucr = ToneCurve.BuildGamma(null, gammaUcr)) using (var bg = ToneCurve.BuildGamma(null, gammaBg)) using (var desc = MultiLocalizedUnicode.Create(null)) { desc.SetASCII(languageCode, countryCode, expectedText); var target = new UcrBg(ucr, bg, desc); using (var profile = Profile.CreatePlaceholder(null)) { profile.WriteTag(TagSignature.UcrBg, target); // Act var actual = profile.ReadTag <UcrBg>(TagSignature.UcrBg); var actualUcr = actual.Ucr; var actualBg = actual.Bg; var actualDesc = actual.Desc; // Assert Assert.IsNotNull(actualUcr); Assert.IsNotNull(actualBg); Assert.IsNotNull(actualDesc); var actualText = actualDesc.GetASCII(languageCode, countryCode); Assert.AreEqual(expectedText, actualText); } } }
public void FromHandleTest() { // Arrange int expected = 3; using (var profile = Profile.CreatePlaceholder(null)) { using (var dict = Dict.Create(null)) using (var mlu = MultiLocalizedUnicode.Create(null, 0)) { mlu.SetASCII("en", "GB", "Hello"); dict.Add("first", null, null, null); dict.Add("second", "second-value", null, null); dict.Add("third", "third-value", mlu, null); profile.WriteTag(TagSignature.Meta, dict.Handle); } // Act using (var roDict = Dict.FromHandle(profile.ReadTag(TagSignature.Meta))) { // Assert int actual = roDict.Count(); Assert.AreEqual(expected, actual); } } }
public void ConstructorTest() { // Arrange int type = 4; double[] parameters = new double[] { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 }; double gamma = 2.2; uint nItems = 0; string languageCode = "en"; string countryCode = "US"; string text = "constructor"; using (var expectedUcr = ToneCurve.BuildParametric(null, type, parameters)) using (var expectedBg = ToneCurve.BuildGamma(null, gamma)) using (var expectedDesc = MultiLocalizedUnicode.Create(null, nItems)) { expectedDesc.SetASCII(languageCode, countryCode, text); // Act var target = new UcrBg(expectedUcr, expectedBg, expectedDesc); var actualUcr = target.Ucr; var actualBg = target.Bg; var actualDesc = target.Desc; // Assert Assert.AreSame(expectedUcr, actualUcr); Assert.AreSame(expectedBg, actualBg); Assert.AreSame(expectedDesc, actualDesc); } }
public void ConstructorTest() { // Arrange int type = 4; double[] parameters = new double[] { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 }; double gamma = 2.2; uint nItems = 0; string languageCode = "en"; string countryCode = "US"; string text = "constructor"; using (var context = Context.Create(IntPtr.Zero, IntPtr.Zero)) using (var ucr = ToneCurve.BuildParametric(context, type, parameters)) using (var bg = ToneCurve.BuildGamma(context, gamma)) using (var desc = MultiLocalizedUnicode.Create(context, nItems)) { desc.SetASCII(languageCode, countryCode, text); var expectedUcr = ucr.Handle; var expectedBg = bg.Handle; var expectedDesc = desc.Handle; // Act var target = new UcrBg(ucr, bg, desc); var actualUcr = target.Ucr; var actualBg = target.Bg; var actualDesc = target.Desc; // Assert Assert.AreEqual(expectedUcr, actualUcr); Assert.AreEqual(expectedBg, actualBg); Assert.AreEqual(expectedDesc, actualDesc); } }
public void PluginTagTest() { // Arrange const TagSignature SignaturelNET = (TagSignature)0x6C4E4554; // 'lNET' PluginTag tag = new PluginTag { Base = new PluginBase { Magic = Cms.PluginMagicNumber, ExpectedVersion = (uint)Cms.EncodedCMMVersion, // >= 2.8 Type = PluginType.Tag, Next = IntPtr.Zero }, Signature = SignaturelNET, Descriptor = new TagDescriptor { ElemCount = 1, nSupportedTypes = 1, SupportedTypes = new TagTypeSignature[TagDescriptor.MAX_TYPES_IN_LCMS_PLUGIN], Decider = IntPtr.Zero } }; tag.Descriptor.SupportedTypes[0] = TagTypeSignature.Text; string expected = "PluginTagTest"; // Act int rawsize = Marshal.SizeOf(tag); IntPtr plugin = Marshal.AllocHGlobal(rawsize); Marshal.StructureToPtr(tag, plugin, false); try { using (var context = Context.Create(plugin, IntPtr.Zero)) using (var profile = Profile.CreatePlaceholder(context)) { using (var mlu = MultiLocalizedUnicode.Create(context)) { mlu.SetASCII(MultiLocalizedUnicode.NoLanguage, MultiLocalizedUnicode.NoCountry, expected); bool written = profile.WriteTag(SignaturelNET, mlu); Assert.IsTrue(written); } using (var mlu = profile.ReadTag <MultiLocalizedUnicode>(SignaturelNET)) { var actual = mlu.GetASCII(MultiLocalizedUnicode.NoLanguage, MultiLocalizedUnicode.NoCountry); // Assert Assert.AreEqual(expected, actual); } } } finally { Marshal.DestroyStructure(plugin, typeof(PluginTag)); Marshal.FreeHGlobal(plugin); } }
// //You can use the following additional attributes as you write your tests: // //Use ClassInitialize to run code before running the first test in the class //[ClassInitialize()] //public static void MyClassInitialize(TestContext testContext) //{ //} // //Use ClassCleanup to run code after all tests in a class have run //[ClassCleanup()] //public static void MyClassCleanup() //{ //} // //Use TestInitialize to run code before running each test //[TestInitialize()] //public void MyTestInitialize() //{ //} // //Use TestCleanup to run code after each test has run //[TestCleanup()] //public void MyTestCleanup() //{ //} // #endregion MultiLocalizedUnicode Create(string enUS, string esES) { var mlu = MultiLocalizedUnicode.Create(null, 0); mlu.SetWide("en", "US", enUS); mlu.SetWide("es", "ES", esES); return(mlu); }
public void GetWideTestNonExistent() { // Arrange using (var mlu = MultiLocalizedUnicode.Create(null)) { // Act var actual = mlu.GetWide("en", "US"); // Assert Assert.IsNull(actual); } }
public void CreateTest() { // Arrange IntPtr plugin = IntPtr.Zero; IntPtr userData = IntPtr.Zero; uint nItems = 3; // Act using (var context = Context.Create(plugin, userData)) using (var mlu = MultiLocalizedUnicode.Create(context, nItems)) { // Assert Assert.IsNotNull(mlu); } }
public void FromHandleTest() { // Arrange int type = 4; double[] parameters = new double[] { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 }; double gamma = 2.2; uint nItems = 0; string languageCode = "en"; string countryCode = "US"; string expectedText = "from-handle"; using (var context = Context.Create(IntPtr.Zero, IntPtr.Zero)) using (var ucr = ToneCurve.BuildParametric(context, type, parameters)) using (var bg = ToneCurve.BuildGamma(context, gamma)) using (var desc = MultiLocalizedUnicode.Create(context, nItems)) { desc.SetASCII(languageCode, countryCode, expectedText); var notExpectedUcr = IntPtr.Zero; var notExpectedBg = IntPtr.Zero; var notExpectedDesc = IntPtr.Zero; var target = new UcrBg(ucr, bg, desc); using (var profile = Profile.CreatePlaceholder(null)) { profile.WriteTag(TagSignature.UcrBg, target); IntPtr handle = profile.ReadTag(TagSignature.UcrBg); // Act var actual = UcrBg.FromHandle(handle); var actualUcr = actual.Ucr; var actualBg = actual.Bg; var actualDesc = actual.Desc; // Assert Assert.AreNotEqual(notExpectedUcr, actualUcr); Assert.AreNotEqual(notExpectedBg, actualBg); Assert.AreNotEqual(notExpectedDesc, actualDesc); var desc2 = MultiLocalizedUnicode.FromHandle(actualDesc); var actualText = desc2.GetASCII(languageCode, countryCode); Assert.AreEqual(expectedText, actualText); } } }
public void GetTranslationTestNonExistent() { // Arrange string expectedLanguageCode = null; string expectedCountryCode = null; using (var mlu = MultiLocalizedUnicode.Create(null)) { // Act var actual = mlu.GetTranslation("en", "US", out string actualLanguageCode, out string actualCountryCode); // Assert Assert.IsFalse(actual); Assert.AreEqual(expectedLanguageCode, actualLanguageCode); Assert.AreEqual(expectedCountryCode, actualCountryCode); } }
public void FromHandleTest() { // Arrange string expected = "sRGB IEC61966-2.1"; using (MemoryStream ms = Save(".Resources.sRGB.icc")) { using (var profile = Profile.Open(ms.GetBuffer())) using (var mlu = MultiLocalizedUnicode.FromHandle(profile.ReadTag(TagSignature.ProfileDescription))) { // Act string actual = mlu.GetASCII(MultiLocalizedUnicode.NoLanguage, MultiLocalizedUnicode.NoCountry); // Assert Assert.AreEqual(expected, actual); } } }
public void AddTest() { // Arrange string name = "name"; string value = "value"; using (var dict = Dict.Create(null)) using (var displayName = MultiLocalizedUnicode.Create(null, 0)) { displayName.SetWide("en", "US", "Hello"); // Act bool added = dict.Add(name, value, displayName, null); // Assert Assert.IsTrue(added); } }
public void TranslationsCodesTestIndexOutOfRange() { // Arrange uint index = 3; string expectedLanguageCode = null; string expectedCountryCode = null; using (var mlu = MultiLocalizedUnicode.Create(null)) { // Act var actual = mlu.TranslationsCodes(index, out string actualLanguageCode, out string actualCountryCode); // Assert Assert.IsFalse(actual); Assert.AreEqual(expectedLanguageCode, actualLanguageCode); Assert.AreEqual(expectedCountryCode, actualCountryCode); } }
public void TranslationsCodesTestNoLanguageNoCountry() { // Arrange var expectedLanguageCode = MultiLocalizedUnicode.NoLanguage; var expectedCountryCode = MultiLocalizedUnicode.NoCountry; uint index = 0; using (var mlu = MultiLocalizedUnicode.Create(null)) { mlu.SetASCII(expectedLanguageCode, expectedCountryCode, "TranslationsCodes"); // Act var actual = mlu.TranslationsCodes(index, out string actualLanguageCode, out string actualCountryCode); // Assert Assert.AreEqual(expectedLanguageCode, actualLanguageCode); Assert.AreEqual(expectedCountryCode, actualCountryCode); } }
public void SetWideTest() { // Arrange IntPtr plugin = IntPtr.Zero; IntPtr userData = IntPtr.Zero; uint nItems = 0; string languageCode = "en"; string countryCode = "US"; // Act using (var context = Context.Create(plugin, userData)) using (var mlu = MultiLocalizedUnicode.Create(context, nItems)) { bool set = mlu.SetWide(languageCode, countryCode, "SetWide"); // Assert Assert.IsTrue(set); } }
public void GetTranslationTestNoMatch() { // Arrange var expectedLanguageCode = "en"; var expectedCountryCode = "US"; using (var mlu = MultiLocalizedUnicode.Create(null)) { mlu.SetASCII(expectedLanguageCode, expectedCountryCode, "Apple"); // Act var actual = mlu.GetTranslation("fr", "FR", out string actualLanguageCode, out string actualCountryCode); // Assert Assert.IsTrue(actual); Assert.AreEqual(expectedLanguageCode, actualLanguageCode); Assert.AreEqual(expectedCountryCode, actualCountryCode); } }
public void DuplicateTest() { // Arrange IntPtr plugin = IntPtr.Zero; IntPtr userData = IntPtr.Zero; uint nItems = 0; // Act using (var context = Context.Create(plugin, userData)) using (var mlu = MultiLocalizedUnicode.Create(context, nItems)) { mlu.SetASCII(MultiLocalizedUnicode.NoLanguage, MultiLocalizedUnicode.NoCountry, "Duplicate"); using (var duplicate = mlu.Duplicate()) { // Assert Assert.IsNotNull(duplicate); } } }
public void TranslationsCountTest() { // Arrange IntPtr plugin = IntPtr.Zero; IntPtr userData = IntPtr.Zero; uint nItems = 0; string languageCode = "en"; string countryCode = "US"; uint notExpected = 0; // Act using (var context = Context.Create(plugin, userData)) using (var mlu = MultiLocalizedUnicode.Create(context, nItems)) { mlu.SetASCII(languageCode, countryCode, "TranslationsCount"); var actual = mlu.TranslationsCount; // Assert Assert.AreNotEqual(notExpected, actual); } }
public void GetWideTest() { // Arrange IntPtr plugin = IntPtr.Zero; IntPtr userData = IntPtr.Zero; uint nItems = 0; string languageCode = "en"; string countryCode = "US"; string expected = "GetWide"; // Act using (var context = Context.Create(plugin, userData)) using (var mlu = MultiLocalizedUnicode.Create(context, nItems)) { mlu.SetWide(languageCode, countryCode, expected); var actual = mlu.GetWide(languageCode, countryCode); // Assert Assert.AreEqual(expected, actual); } }
public void EnumerateTest() { // Arrange using (var dict = Dict.Create(null)) using (var mlu = MultiLocalizedUnicode.Create(null, 0)) { mlu.SetASCII("en", "GB", "Hello"); dict.Add("first", null, null, null); dict.Add("second", "second-value", null, null); dict.Add("third", "third-value", mlu, null); int expected = 3; // Act var actual = dict.Count(); var list = dict.ToArray(); // Assert Assert.AreEqual(expected, actual); } }
public void TranslationsCodeTest() { // Arrange IntPtr plugin = IntPtr.Zero; IntPtr userData = IntPtr.Zero; uint nItems = 0; string expectedLanguageCode = "en"; string expectedCountryCode = "US"; uint index = 0; // Act using (var context = Context.Create(plugin, userData)) using (var mlu = MultiLocalizedUnicode.Create(context, nItems)) { mlu.SetASCII(expectedLanguageCode, expectedCountryCode, "TranslationsCount"); var actual = mlu.TranslationsCodes(index, out string actualLanguageCode, out string actualCountryCode); // Assert Assert.AreEqual(expectedLanguageCode, actualLanguageCode); Assert.AreEqual(expectedCountryCode, actualCountryCode); } }
public void DescriptionSetTest() { // Arrange uint nItems = 3; string languageCode = "en"; string countryCode = "US"; string expected = "Description"; using (var psd = ProfileSequenceDescriptor.Create(null, nItems)) using (var mlu = MultiLocalizedUnicode.Create(null, 1)) { mlu.SetASCII(languageCode, countryCode, expected); ProfileSequenceItem item = psd[2]; // Act item.Description = mlu; // Assert string actual = item.Description.GetASCII(languageCode, countryCode); Assert.AreEqual(expected, actual); } }
public void ManufacturerSetTest() { // Arrange uint nItems = 3; string languageCode = "en"; string countryCode = "US"; string expected = "Manufacturer"; using (var psd = ProfileSequenceDescriptor.Create(null, nItems)) using (var mlu = MultiLocalizedUnicode.Create(null, 1)) { mlu.SetASCII(languageCode, countryCode, expected); ProfileSequenceItem item = psd[0]; // Act item.Manufacturer = mlu; // Assert Assert.IsTrue(mlu.IsClosed); string actual = item.Manufacturer.GetASCII(languageCode, countryCode); Assert.AreEqual(expected, actual); } }
public void PluginTagWithDeciderTest() { // Arrange const TagSignature SignaturelNET = (TagSignature)0x6C4E4554; // 'lNET' // ensure delegates are not garbage collected from managed code var decide = new DecideType(Decide); PluginTag tag = new PluginTag { Base = new PluginBase { Magic = Cms.PluginMagicNumber, ExpectedVersion = (uint)Cms.EncodedCMMVersion, // >= 2.8 Type = PluginType.Tag, Next = IntPtr.Zero }, Signature = SignaturelNET, Descriptor = new TagDescriptor { ElemCount = 1, nSupportedTypes = 1, SupportedTypes = new TagTypeSignature[TagDescriptor.MAX_TYPES_IN_LCMS_PLUGIN], Decider = Marshal.GetFunctionPointerForDelegate(decide) } }; tag.Descriptor.SupportedTypes[0] = TagTypeSignature.Text; string expected = "PluginTagWithDeciderTest"; // Act int rawsize = Marshal.SizeOf(tag); IntPtr plugin = Marshal.AllocHGlobal(rawsize); Marshal.StructureToPtr(tag, plugin, false); try { using (var context = Context.Create(plugin, IntPtr.Zero)) using (var profile = Profile.CreatePlaceholder(context)) { using (var mlu = MultiLocalizedUnicode.Create(context)) { mlu.SetASCII(MultiLocalizedUnicode.NoLanguage, MultiLocalizedUnicode.NoCountry, expected); bool written = profile.WriteTag(SignaturelNET, mlu); Assert.IsTrue(written); } using (var mlu = profile.ReadTag <MultiLocalizedUnicode>(SignaturelNET)) { var actual = mlu.GetASCII(MultiLocalizedUnicode.NoLanguage, MultiLocalizedUnicode.NoCountry); // Assert Assert.AreEqual(expected, actual); } } } finally { Marshal.DestroyStructure(plugin, typeof(PluginTag)); Marshal.FreeHGlobal(plugin); } TagTypeSignature Decide(double iccVersion, IntPtr data) { TestContext.WriteLine($"iccVersion: {iccVersion}, data: 0x{data:X}"); using (var mlu = MultiLocalizedUnicode.FromHandle(data)) { var text = mlu.GetASCII(MultiLocalizedUnicode.NoLanguage, MultiLocalizedUnicode.NoCountry); TestContext.WriteLine($"text: {text}"); } return(TagTypeSignature.Text); } }