Commit 857647e9 authored by 16이상민's avatar 16이상민

Edit test: SourceBufferTests, I wrote the test in a completely incorrect way :(

parent f21dfc57
......@@ -18,14 +18,4 @@ public class KinectAccessManagerTests
_KinectAccessManager.Dispose();
Assert.IsFalse(_KinectAccessManager.IsAccess, "Kinect Dispose Error.");
}
// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[UnityTest]
public IEnumerator KinectAccessManagerTestsWithEnumeratorPasses()
{
// Use the Assert class to test conditions.
// yield to skip a frame
yield return null;
}
}
......@@ -4,90 +4,121 @@ using System.Collections;
using Windows.Kinect;
using System.Runtime.InteropServices;
using KinectModule;
using System.Collections.Generic;
using System.Linq;
using System;
// To test the update function and the updated buffer, you need a stub for the source frame class.
public class SourceBufferTests
{
KinectAccessManager _KinectAccessManager = new KinectAccessManager();
SourceBuffer _SourceBuffer = new SourceBuffer();
[Test]
public void ColorBuffer_NotEqual_Null()
{
var obj = new SourceBuffer();
var expected = null as byte[];
var actual = obj.ColorBuffer;
Assert.AreNotEqual(expected, actual, "ColorBuffer should not be null value.");
}
[Test]
public void SourceBufferTestsSimplePasses()
public void BodyIndexBuffer_NotEqual_Null()
{
// Use the Assert class to test conditions.
var obj = new SourceBuffer();
var expected = null as byte[];
var actual = obj.BodyIndexBuffer;
_KinectAccessManager.Access();
Assert.IsTrue(_KinectAccessManager.IsAccess, "Kinect Access Error.");
Assert.AreNotEqual(expected, actual, "BodyIndexBuffer should not be null value.");
}
var sourceFrame = _KinectAccessManager.SourceFrame;
_SourceBuffer.UpdateBuffers(sourceFrame);
[Test]
public void DepthBuffer_NotEqual_Null()
{
var obj = new SourceBuffer();
ColorBufferTest(sourceFrame);
BodyIndexBufferTest(sourceFrame);
DepthBufferTest(sourceFrame);
BodyBufferTest(sourceFrame);
var expected = null as ushort[];
var actual = obj.DepthBuffer;
_KinectAccessManager.Dispose();
Assert.AreNotEqual(expected, actual, "DepthBuffer should not be null value.");
}
private void ColorBufferTest(MultiSourceFrame sourceFrame)
[Test]
public void BodyBuffer_NotEqual_Null()
{
var colorBuffer = new byte[SourceBuffer.ColorWidth * SourceBuffer.ColorHeight * 4];
using (var colorFrame = sourceFrame.ColorFrameReference.AcquireFrame())
if (colorFrame != null)
{
var ColorData = GCHandle.Alloc(colorBuffer, GCHandleType.Pinned);
colorFrame.CopyConvertedFrameDataToIntPtr(ColorData.AddrOfPinnedObject(), (uint)colorBuffer.Length, ColorImageFormat.Rgba);
ColorData.Free();
}
Assert.AreEqual(colorBuffer, _SourceBuffer.ColorBuffer, "ColorBufferTest failed.");
var obj = new SourceBuffer();
var expected = null as Body[];
var actual = obj.BodyBuffer;
Assert.AreNotEqual(expected, actual, "BodyBuffer should not be null value.");
}
private void BodyIndexBufferTest(MultiSourceFrame sourceFrame)
[Test]
public void ColorBuffer_Equal_Green()
{
var bodyIndexBuffer = new byte[SourceBuffer.DepthWidth * SourceBuffer.DepthHeight];
using (var bodyIndexFrame = sourceFrame.BodyIndexFrameReference.AcquireFrame())
if (bodyIndexFrame != null)
{
var BodyIndexData = GCHandle.Alloc(bodyIndexBuffer, GCHandleType.Pinned);
bodyIndexFrame.CopyFrameDataToIntPtr(BodyIndexData.AddrOfPinnedObject(), (uint)bodyIndexBuffer.Length);
BodyIndexData.Free();
}
Assert.AreEqual(bodyIndexBuffer, _SourceBuffer.BodyIndexBuffer, "BodyIndexBufferTest failed.");
var frame = new GreenFrameStub();
var obj = new SourceBuffer();
obj.UpdateBuffers(frame);
var expected = new byte[KinectConstants.ColorWidth *
KinectConstants.ColorHeight *
KinectConstants.ColorCount];
frame.LastColorFrame.CopyData(expected);
var actual = obj.ColorBuffer;
Assert.AreEqual(expected, actual, "Colorbuffer should be filled with green.");
}
}
public class GreenFrameStub : IMultiSourceFrame
{
private GreenColorFrameStub _ColorFrame = new GreenColorFrameStub();
private BodyIndexFrameDummy _BodyIndexFrame = new BodyIndexFrameDummy();
private DepthFrameDummy _DepthFrame = new DepthFrameDummy();
private BodyFrameDummy _BodyFrame = new BodyFrameDummy();
private void DepthBufferTest(MultiSourceFrame sourceFrame)
public IColorFrame LastColorFrame
{ get { return _ColorFrame; } }
public IBodyIndexFrame LastBodyIndexFrame
{ get { return _BodyIndexFrame; } }
public IDepthFrame LastDepthFrame
{ get { return _DepthFrame; } }
public IBodyFrame LastBodyFrame
{ get { return _BodyFrame; } }
private class GreenColorFrameStub : IColorFrame
{
var depthBuffer = new ushort[SourceBuffer.DepthWidth * SourceBuffer.DepthHeight];
using (var depthFrame = sourceFrame.DepthFrameReference.AcquireFrame())
if (depthFrame != null)
{
var DepthData = GCHandle.Alloc(depthBuffer, GCHandleType.Pinned);
depthFrame.CopyFrameDataToIntPtr(DepthData.AddrOfPinnedObject(), (uint)depthBuffer.Length * sizeof(ushort));
DepthData.Free();
}
Assert.AreEqual(depthBuffer, _SourceBuffer.DepthBuffer, "DepthBufferTest failed.");
private static uint[] data =
Enumerable.Repeat<uint>(0x00FF00FF,
KinectConstants.ColorWidth *
KinectConstants.ColorHeight).ToArray<uint>();
public void CopyData(byte[] buffer)
{
Buffer.BlockCopy(buffer, 0, data, 0, buffer.Length);
}
}
private void BodyBufferTest(MultiSourceFrame sourceFrame)
private class BodyIndexFrameDummy : IBodyIndexFrame
{
var bodyBuffer = new Body[SourceBuffer.BodyCount];
using (var bodyFrame = sourceFrame.BodyFrameReference.AcquireFrame())
if (bodyFrame != null)
bodyFrame.GetAndRefreshBodyData(bodyBuffer);
public void CopyData(byte[] buffer)
{ }
}
Assert.AreEqual(bodyBuffer, _SourceBuffer.BodyBuffer, "BodyBufferTest failed.");
private class DepthFrameDummy : IDepthFrame
{
public void CopyData(ushort[] buffer)
{ }
}
// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[UnityTest]
public IEnumerator SourceBufferTestsWithEnumeratorPasses()
private class BodyFrameDummy : IBodyFrame
{
// Use the Assert class to test conditions.
// yield to skip a frame
yield return null;
}
}
public void CopyData(Body[] buffer)
{ }
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -15,22 +15,16 @@ public class CoordinateMapperView : MonoBehaviour
CoordinateMapperManager CoordinateMapperManager = GameObject.Find("Managers").GetComponent<CoordinateMapperManager>();
GetComponent<Renderer>().material.SetTexture("_MainTex", CoordinateMapperManager.ColorTexture);
DepthBuffer = GenerateBuffer("depthCoordinates", sizeof(float) * 2, (DepthPoints = CoordinateMapperManager.DepthCoordinates));
BodyIndexBuffer = GenerateBuffer("BodyIndexBuffer", sizeof(float), (BodyIndexPoints = CoordinateMapperManager.BodyIndexBuffer));
}
Func<Array, Array, Action<string, ComputeBuffer, int>> setBuffer = (srcPoints, dstPoints) =>
{
dstPoints = srcPoints;
return (name, buffer, stride) =>
{
buffer = new ComputeBuffer(dstPoints.Length, stride);
GetComponent<Renderer>().material.SetBuffer(name, buffer);
};
};
setBuffer(CoordinateMapperManager.DepthCoordinates, DepthPoints)
("depthCoordinates", DepthBuffer, sizeof(float) * 2);
setBuffer(CoordinateMapperManager.BodyIndexBuffer, BodyIndexPoints)
("BodyIndexBuffer", BodyIndexBuffer, sizeof(float));
ComputeBuffer GenerateBuffer(string name, int stride, Array points)
{
var buffer = new ComputeBuffer(points.Length, stride);
GetComponent<Renderer>().material.SetBuffer(name, buffer);
return buffer;
}
void Update()
......@@ -45,8 +39,5 @@ public class CoordinateMapperView : MonoBehaviour
{
DepthBuffer.Release();
BodyIndexBuffer.Release();
DepthPoints = null;
BodyIndexPoints = null;
}
}
......@@ -6,7 +6,7 @@ using UnityEngine.UI;
using Windows.Kinect;
public class MotionView : MonoBehaviour {
Pair<float, MotionState> recent;
Pair<float, MotionState> _Recent;
public GameObject CoordinateMapperManager;
CoordinateMapperManager _coordinateMapperManager;
Body[] body;
......@@ -17,13 +17,13 @@ public class MotionView : MonoBehaviour {
kneeRightBase;
bool IsInitialized;
public Pair<float, MotionState> RecentState
{ get { return recent; } }
public Pair<float, MotionState> Recent
{ get { return _Recent; } }
// Use this for initialization
void Start ()
{
recent = new Pair<float, MotionState>
_Recent = new Pair<float, MotionState>
{
first = 0,
second = MotionState.UNKNOWN
......@@ -42,10 +42,10 @@ public class MotionView : MonoBehaviour {
// Update is called once per frame
void Update ()
{
recent.first += Time.deltaTime;
recent.second = DetermineState();
_Recent.first += Time.deltaTime;
_Recent.second = DetermineState();
InputManager.Instance.CurrentMotionState = recent.second;
InputManager.Instance.CurrentMotionState = _Recent.second;
}
MotionState DetermineState()
......
fileFormatVersion: 2
guid: c28398155b106d94db55ece60bf7890b
folderAsset: yes
timeCreated: 1515375347
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
using Windows.Kinect;
using System.Runtime.InteropServices;
using System;
public class CoordinateMapperManagerTests {
[Test]
public void CoordinateMapperManagerTestsSimplePasses() {
// Use the Assert class to test conditions.
}
// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[UnityTest]
public IEnumerator InterfaceTest() {
// Use the Assert class to test conditions.
// yield to skip a frame
yield return null;
}
[UnityTest]
public IEnumerator FPSTest()
{
yield return null;
}
}
fileFormatVersion: 2
guid: b1d6a9e0d1a234f4292f6a346b18d2ec
timeCreated: 1515375333
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using UnityEngine.TestTools;
using NUnit.Framework;
using System.Collections;
using Windows.Kinect;
using System.Runtime.InteropServices;
using System;
namespace Assets.Script.Tests
{
class CoordinateMapperViewTests
{
[Test]
public void CoordinateMapperViewTestsSimplePasses()
{
// Use the Assert class to test conditions.
}
// A UnityTest behaves like a coroutine in PlayMode
// and allows you to yield null to skip a frame in EditMode
[UnityTest]
public IEnumerator CoordinateMapperViewTestsWithEnumeratorPasses()
{
var CoordinateMapperManager = GameObject.Find("Managers").GetComponent<CoordinateMapperManager>();
var tmpObj = GameObject.CreatePrimitive(PrimitiveType.Plane);
tmpObj.GetComponent<Renderer>().material = Resources.Load("GreenScreen/GreenScreen.mat", typeof(Material)) as Material;
tmpObj.GetComponent<Renderer>().material.SetTexture("_MainTex", CoordinateMapperManager.ColorTexture);
var DepthPoints = CoordinateMapperManager.DepthCoordinates;
var DepthBuffer = new ComputeBuffer(DepthPoints.Length, sizeof(float) * 2);
tmpObj.GetComponent<Renderer>().material.SetBuffer("depthCoordinates", DepthBuffer);
var BodyIndexPoints = CoordinateMapperManager.BodyIndexBuffer;
var BodyIndexBuffer = new ComputeBuffer(BodyIndexPoints.Length, sizeof(float));
tmpObj.GetComponent<Renderer>().material.SetBuffer("bodyIndexBuffer", BodyIndexBuffer);
var CoordinateMapperView = GameObject.Find("CoordinateMapView");
// Use the Assert class to test conditions.
// yield to skip a frame
yield return null;
Assert.AreEqual(tmpObj.GetComponent<Renderer>().material.mainTexture, CoordinateMapperView.GetComponent<Renderer>().material.mainTexture, "CoordinateMapperViewTest Failed.");
}
}
}
fileFormatVersion: 2
guid: 623524eedad81b24c9da54ab55e5e468
timeCreated: 1515385568
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -295,7 +295,7 @@ PlayerSettings:
wiiUGamePadStartupScreen: {fileID: 0}
wiiUDrcBufferDisabled: 0
wiiUProfilerLibPath:
playModeTestRunnerEnabled: 0
playModeTestRunnerEnabled: 1
actionOnDotNetUnhandledException: 1
enableInternalProfiler: 0
logObjCUncaughtExceptions: 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment