BasicAssetTest.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using log4net.Config;
  30. using NUnit.Framework;
  31. using NUnit.Framework.SyntaxHelpers;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using log4net;
  35. namespace OpenSim.Data.Tests
  36. {
  37. public class BasicAssetTest
  38. {
  39. public IAssetDataPlugin db;
  40. public UUID uuid1;
  41. public UUID uuid2;
  42. public UUID uuid3;
  43. public byte[] asset1;
  44. public void SuperInit()
  45. {
  46. OpenSim.Tests.Common.TestLogging.LogToConsole();
  47. uuid1 = UUID.Random();
  48. uuid2 = UUID.Random();
  49. uuid3 = UUID.Random();
  50. asset1 = new byte[100];
  51. asset1.Initialize();
  52. }
  53. [Test]
  54. public void T001_LoadEmpty()
  55. {
  56. Assert.That(db.ExistsAsset(uuid1), Is.False);
  57. Assert.That(db.ExistsAsset(uuid2), Is.False);
  58. Assert.That(db.ExistsAsset(uuid3), Is.False);
  59. }
  60. [Test]
  61. public void T010_StoreSimpleAsset()
  62. {
  63. AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture);
  64. AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture);
  65. AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture);
  66. a1.Data = asset1;
  67. a2.Data = asset1;
  68. a3.Data = asset1;
  69. PropertyScrambler<AssetBase> scrambler = new PropertyScrambler<AssetBase>()
  70. .DontScramble(x => x.Data)
  71. .DontScramble(x => x.ID)
  72. .DontScramble(x => x.FullID)
  73. .DontScramble(x => x.Metadata.ID)
  74. .DontScramble(x => x.Metadata.FullID);
  75. scrambler.Scramble(a1);
  76. scrambler.Scramble(a2);
  77. scrambler.Scramble(a3);
  78. db.StoreAsset(a1);
  79. db.StoreAsset(a2);
  80. db.StoreAsset(a3);
  81. AssetBase a1a = db.GetAsset(uuid1);
  82. Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
  83. AssetBase a2a = db.GetAsset(uuid2);
  84. Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
  85. AssetBase a3a = db.GetAsset(uuid3);
  86. Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
  87. scrambler.Scramble(a1a);
  88. scrambler.Scramble(a2a);
  89. scrambler.Scramble(a3a);
  90. db.StoreAsset(a1a);
  91. db.StoreAsset(a2a);
  92. db.StoreAsset(a3a);
  93. AssetBase a1b = db.GetAsset(uuid1);
  94. Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a));
  95. AssetBase a2b = db.GetAsset(uuid2);
  96. Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a));
  97. AssetBase a3b = db.GetAsset(uuid3);
  98. Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a));
  99. Assert.That(db.ExistsAsset(uuid1), Is.True);
  100. Assert.That(db.ExistsAsset(uuid2), Is.True);
  101. Assert.That(db.ExistsAsset(uuid3), Is.True);
  102. List<AssetMetadata> metadatas = db.FetchAssetMetadataSet(0, 1000);
  103. AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1);
  104. Assert.That(metadata.Name, Is.EqualTo(a1b.Name));
  105. Assert.That(metadata.Description, Is.EqualTo(a1b.Description));
  106. Assert.That(metadata.Type, Is.EqualTo(a1b.Type));
  107. Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary));
  108. Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID));
  109. }
  110. }
  111. }