Skip to content

Commit c8ee08e

Browse files
Issue #15 should be fixed correctly this time. Unittest included.
Signed-off-by: David Rebbe <drebbe@intrepidcs.com>
1 parent c6c8645 commit c8ee08e

2 files changed

Lines changed: 101 additions & 2 deletions

File tree

src/methods.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,19 @@ PyObject* meth_find_devices(PyObject* self, PyObject* args, PyObject* keywords)
176176
NeoDevice devices[255];
177177
int count = 255;
178178
unsigned long legacy_dev_type = 0xFFFFBFFF;
179+
bool use_legacy_device_type = false;
179180
if (device_type && PyLong_Check(device_type))
180181
{
181182
legacy_dev_type = PyLong_AsLong(device_type);
183+
use_legacy_device_type = true;
182184
}
183185
try
184186
{
185187
#ifndef USE_LEGACY_FIND_DEVICES
186188
// Get the list of device types
187189
unsigned int* device_type_list = NULL;
188190
unsigned int device_type_list_size = 0;
189-
if (device_type && device_type != Py_None)
191+
if (!use_legacy_device_type && device_type && device_type != Py_None)
190192
{
191193
std::vector<PyObject*> device_type_vector;
192194
if (!_convertListOrTupleToArray(device_type, &device_type_vector))
@@ -199,6 +201,8 @@ PyObject* meth_find_devices(PyObject* self, PyObject* args, PyObject* keywords)
199201
Py_BEGIN_ALLOW_THREADS
200202
try
201203
{
204+
if (use_legacy_device_type)
205+
throw ice::Exception("Use Legacy Function!");
202206
if (ex_options != -1)
203207
throw ice::Exception("Need to use old style find function");
204208
//int _stdcall icsneoFindNeoDevicesNewStyle(unsigned int* deviceTypes, unsigned int numDeviceTypes, NeoDevice* pNeoDevice, int* pNumDevices)

test/test_find_devices.py

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,98 @@
11
import timeit
2+
import unittest
3+
import ics
4+
# This test requries 2 devices attached, one neoVI FIRE2s and one ValueCAN3
25

3-
print(timeit.timeit("ics.find_devices()", setup="import ics", number=1000))
6+
_DEBUG = False
7+
8+
class TestFindDevicesLegacy(unittest.TestCase):
9+
@classmethod
10+
def setUpClass(self):
11+
ics.override_library_name(r"C:\Windows\SysWOW64\icsneo40-legacy.dll")
12+
if _DEBUG:
13+
import os
14+
input("Pause... " + str(os.getpid()))
15+
16+
def test_default_parameters(self):
17+
devices = ics.find_devices()
18+
self.assertTrue(len(devices) == 2)
19+
20+
def test_default_parameters_time(self):
21+
if not _DEBUG:
22+
self.assertTrue((timeit.timeit("ics.find_devices()", setup="import ics", number=1000)) <= 5.0)
23+
24+
def test_find_fire2(self):
25+
devices = ics.find_devices(ics.NEODEVICE_FIRE2)
26+
self.assertTrue(len(devices) == 1)
27+
28+
def test_find_vcan3(self):
29+
devices = ics.find_devices(ics.NEODEVICE_VCAN3)
30+
self.assertTrue(len(devices) == 1)
31+
32+
def test_find_fire2_and_vcan3(self):
33+
devices = ics.find_devices(ics.NEODEVICE_FIRE2 | ics.NEODEVICE_VCAN3)
34+
self.assertTrue(len(devices) == 2)
35+
36+
class TestFindDevicesNewStyle(unittest.TestCase):
37+
@classmethod
38+
def setUpClass(self):
39+
ics.override_library_name(r"C:\Windows\SysWOW64\icsneo40.dll")
40+
if _DEBUG:
41+
import os
42+
input("Pause... " + str(os.getpid()))
43+
44+
def test_default_parameters(self):
45+
devices = ics.find_devices()
46+
self.assertTrue(len(devices) == 2)
47+
48+
def test_default_parameters_time(self):
49+
if not _DEBUG:
50+
self.assertTrue((timeit.timeit("ics.find_devices()", setup="import ics", number=1000)) <= 5.0)
51+
52+
def test_find_fire2(self):
53+
devices = ics.find_devices([ics.NEODEVICE_FIRE2,])
54+
self.assertTrue(len(devices) == 1)
55+
56+
def test_find_vcan3(self):
57+
devices = ics.find_devices([ics.NEODEVICE_VCAN3,])
58+
self.assertTrue(len(devices) == 1)
59+
60+
def test_find_fire2_and_vcan3(self):
61+
devices = ics.find_devices([ics.NEODEVICE_FIRE2, ics.NEODEVICE_VCAN3])
62+
self.assertTrue(len(devices) == 2)
63+
64+
65+
class TestFindDevicesNewStyleWithLegacyDLL(unittest.TestCase):
66+
@classmethod
67+
def setUpClass(self):
68+
import ics
69+
ics.override_library_name(r"C:\Windows\SysWOW64\icsneo40-legacy.dll")
70+
if _DEBUG:
71+
import os
72+
input("Pause... " + str(os.getpid()))
73+
74+
def test_default_parameters(self):
75+
devices = ics.find_devices()
76+
self.assertTrue(len(devices) == 2)
77+
78+
def test_default_parameters_time(self):
79+
self.assertTrue((timeit.timeit("ics.find_devices()", setup="import ics", number=1000)) <= 5.0)
80+
81+
def test_find_fire2(self):
82+
devices = ics.find_devices([ics.NEODEVICE_FIRE2,])
83+
self.assertTrue(len(devices) == 2)
84+
85+
def test_find_vcan3(self):
86+
devices = ics.find_devices([ics.NEODEVICE_VCAN3,])
87+
self.assertTrue(len(devices) == 2)
88+
89+
def test_find_fire2_and_vcan3(self):
90+
devices = ics.find_devices([ics.NEODEVICE_FIRE2, ics.NEODEVICE_VCAN3])
91+
self.assertTrue(len(devices) == 2)
92+
93+
94+
if __name__ == "__main__":
95+
if _DEBUG:
96+
import os
97+
input("Pause... " + str(os.getpid()))
98+
unittest.main()

0 commit comments

Comments
 (0)