BasicAssetTest.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 OpenSim 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 NUnit.Framework;
  30. using NUnit.Framework.SyntaxHelpers;
  31. using OpenSim.Data;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.Environment.Scenes;
  34. using OpenMetaverse;
  35. namespace OpenSim.Data.Tests
  36. {
  37. public class BasicAssetTest
  38. {
  39. public AssetDataBase db;
  40. public UUID uuid1;
  41. public UUID uuid2;
  42. public UUID uuid3;
  43. public byte[] asset1;
  44. public void SuperInit()
  45. {
  46. try
  47. {
  48. log4net.Config.XmlConfigurator.Configure();
  49. }
  50. catch (Exception)
  51. {
  52. // I don't care, just leave log4net off
  53. }
  54. uuid1 = UUID.Random();
  55. uuid2 = UUID.Random();
  56. uuid3 = UUID.Random();
  57. asset1 = new byte[100];
  58. asset1.Initialize();
  59. }
  60. [Test]
  61. public void T001_LoadEmpty()
  62. {
  63. Assert.That(db.ExistsAsset(uuid1), Is.False);
  64. Assert.That(db.ExistsAsset(uuid2), Is.False);
  65. Assert.That(db.ExistsAsset(uuid3), Is.False);
  66. }
  67. [Test]
  68. public void T010_StoreSimpleAsset()
  69. {
  70. AssetBase a1 = new AssetBase(uuid1, "asset one");
  71. AssetBase a2 = new AssetBase(uuid2, "asset two");
  72. AssetBase a3 = new AssetBase(uuid3, "asset three");
  73. a1.Data = asset1;
  74. a2.Data = asset1;
  75. a3.Data = asset1;
  76. db.CreateAsset(a1);
  77. db.CreateAsset(a2);
  78. db.CreateAsset(a3);
  79. AssetBase a1a = db.FetchAsset(uuid1);
  80. Assert.That(a1.ID, Is.EqualTo(a1a.ID));
  81. Assert.That(a1.Name, Is.EqualTo(a1a.Name));
  82. AssetBase a2a = db.FetchAsset(uuid2);
  83. Assert.That(a2.ID, Is.EqualTo(a2a.ID));
  84. Assert.That(a2.Name, Is.EqualTo(a2a.Name));
  85. AssetBase a3a = db.FetchAsset(uuid3);
  86. Assert.That(a3.ID, Is.EqualTo(a3a.ID));
  87. Assert.That(a3.Name, Is.EqualTo(a3a.Name));
  88. }
  89. [Test]
  90. public void T011_ExistsSimpleAsset()
  91. {
  92. Assert.That(db.ExistsAsset(uuid1), Is.True);
  93. Assert.That(db.ExistsAsset(uuid2), Is.True);
  94. Assert.That(db.ExistsAsset(uuid3), Is.True);
  95. }
  96. // this has questionable use, but it is in the interface at the moment.
  97. // [Test]
  98. // public void T012_DeleteAsset()
  99. // {
  100. // db.DeleteAsset(uuid1);
  101. // db.DeleteAsset(uuid2);
  102. // db.DeleteAsset(uuid3);
  103. // Assert.That(db.ExistsAsset(uuid1), Is.False);
  104. // Assert.That(db.ExistsAsset(uuid2), Is.False);
  105. // Assert.That(db.ExistsAsset(uuid3), Is.False);
  106. // }
  107. }
  108. }