1from PyObjCTools.TestSupport import *
2from AppKit import *
3import array
4import sys
5
6try:
7    unicode
8except NameError:
9    unicode = str
10
11class TestRegressions (TestCase):
12    def testQualifiersInSignature(self):
13        NSColor.redColor().getRed_green_blue_alpha_(None, None, None, None)
14
15    def testMethods(self):
16        self.assertResultIsBOOL(NSColor.ignoresAlpha)
17        self.assertArgIsBOOL(NSColor.setIgnoresAlpha_, 0)
18
19        space = NSColorSpace.adobeRGB1998ColorSpace()
20        color = NSColor.colorWithColorSpace_components_count_(space, (0.1, 0.2, 0.3, 0.4), 4)
21        self.assertIsInstance(color, NSColor)
22
23        color = NSColor.colorWithCalibratedRed_green_blue_alpha_(0, 0, 0, 0)
24        r, g, b, a = color.getRed_green_blue_alpha_(None, None, None, None)
25        self.assertIsInstance(r, float)
26        self.assertIsInstance(g, float)
27        self.assertIsInstance(b, float)
28        self.assertIsInstance(a, float)
29
30        color = NSColor.colorWithCalibratedHue_saturation_brightness_alpha_(0.1, 0.2, 0.3, 0.4)
31        h, s, b, a = color.getHue_saturation_brightness_alpha_(None, None, None, None)
32        self.assertIsInstance(h, float)
33        self.assertIsInstance(s, float)
34        self.assertIsInstance(b, float)
35        self.assertIsInstance(a, float)
36
37        color = NSColor.colorWithCalibratedWhite_alpha_(0.1, 0.2)
38        w, a = color.getWhite_alpha_(None, None)
39        self.assertIsInstance(w, float)
40        self.assertIsInstance(a, float)
41
42        color = NSColor.colorWithDeviceCyan_magenta_yellow_black_alpha_(1, 1, 1, 1, 1)
43        c, m, y, b, a  = color.getCyan_magenta_yellow_black_alpha_(None, None, None, None, None)
44        self.assertIsInstance(c, float)
45        self.assertIsInstance(m, float)
46        self.assertIsInstance(y, float)
47        self.assertIsInstance(b, float)
48        self.assertIsInstance(a, float)
49
50        if sys.maxsize > 2**32:
51            a = array.array('d', [0] * 6)
52        else:
53            a = array.array('f', [0] * 6)
54        v = color.getComponents_(a)
55        self.assertEqual(a[0], 1.0)
56
57    def testConstants(self):
58        self.assertIsInstance(NSSystemColorsDidChangeNotification, unicode)
59
60        self.assertEqual(NSAppKitVersionNumberWithPatternColorLeakFix, 641.0)
61
62if __name__ == "__main__":
63    main()
64