Exemple #1
0
    def testUpdating(self):
        array = CoreFoundation.CFArrayCreate(
            None, ["a", 2, 3, 4, 4, 2], 6, CoreFoundation.kCFTypeArrayCallBacks
        )
        self.assertEqual(array, ["a", 2, 3, 4, 4, 2])
        self.assertIsInstance(array, CoreFoundation.NSArray)
        array = CoreFoundation.CFArrayCreateMutableCopy(None, 0, array)

        self.assertArgHasType(CoreFoundation.CFArrayAppendValue, 1, b"@")
        self.assertArgHasType(CoreFoundation.CFArrayInsertValueAtIndex, 2, b"@")
        self.assertArgHasType(CoreFoundation.CFArraySetValueAtIndex, 2, b"@")

        CoreFoundation.CFArrayAppendValue(array, "foo")
        self.assertEqual(array, ["a", 2, 3, 4, 4, 2, "foo"])

        CoreFoundation.CFArrayInsertValueAtIndex(array, 1, 4)
        self.assertEqual(array, ["a", 4, 2, 3, 4, 4, 2, "foo"])

        CoreFoundation.CFArrayRemoveValueAtIndex(array, 2)
        self.assertEqual(array, ["a", 4, 3, 4, 4, 2, "foo"])

        CoreFoundation.CFArraySetValueAtIndex(array, 2, "two")
        self.assertEqual(array, ["a", 4, "two", 4, 4, 2, "foo"])

        CoreFoundation.CFArrayExchangeValuesAtIndices(array, 1, 2)
        self.assertEqual(array, ["a", "two", 4, 4, 4, 2, "foo"])

        self.assertArgHasType(CoreFoundation.CFArrayReplaceValues, 2, b"n^@")
        self.assertArgSizeInArg(CoreFoundation.CFArrayReplaceValues, 2, 3)
        CoreFoundation.CFArrayReplaceValues(
            array, (2, 3), ("a", "b", "c", "d", "e", "f"), 6
        )
        self.assertEqual(array, ["a", "two", "a", "b", "c", "d", "e", "f", 2, "foo"])

        array2 = CoreFoundation.CFArrayCreate(
            None, ["hello", "earth"], 2, CoreFoundation.kCFTypeArrayCallBacks
        )
        CoreFoundation.CFArrayAppendArray(array, array2, (0, 2))
        self.assertEqual(
            array,
            ["a", "two", "a", "b", "c", "d", "e", "f", 2, "foo", "hello", "earth"],
        )

        CoreFoundation.CFArrayRemoveAllValues(array)
        self.assertEqual(array, [])
Exemple #2
0
    def testUpdating(self):
        array = CoreFoundation.CFArrayCreate(
            None,
            [b"a".decode("latin1"), 2, 3, 4, 4, 2],
            6,
            CoreFoundation.kCFTypeArrayCallBacks,
        )
        self.assertEqual(array, [b"a".decode("latin1"), 2, 3, 4, 4, 2])
        self.assertIsInstance(array, CoreFoundation.NSArray)
        array = CoreFoundation.CFArrayCreateMutableCopy(None, 0, array)

        self.assertArgHasType(CoreFoundation.CFArrayAppendValue, 1, b"@")
        self.assertArgHasType(CoreFoundation.CFArrayInsertValueAtIndex, 2,
                              b"@")
        self.assertArgHasType(CoreFoundation.CFArraySetValueAtIndex, 2, b"@")

        CoreFoundation.CFArrayAppendValue(array, b"foo".decode("latin1"))
        self.assertEqual(
            array,
            [b"a".decode("latin1"), 2, 3, 4, 4, 2, b"foo".decode("latin1")])

        CoreFoundation.CFArrayInsertValueAtIndex(array, 1, 4)
        self.assertEqual(
            array,
            [b"a".decode("latin1"), 4, 2, 3, 4, 4, 2, b"foo".decode("latin1")])

        CoreFoundation.CFArrayRemoveValueAtIndex(array, 2)
        self.assertEqual(
            array,
            [b"a".decode("latin1"), 4, 3, 4, 4, 2, b"foo".decode("latin1")])

        CoreFoundation.CFArraySetValueAtIndex(array, 2,
                                              b"two".decode("latin1"))
        self.assertEqual(
            array,
            [
                b"a".decode("latin1"),
                4,
                b"two".decode("latin1"),
                4,
                4,
                2,
                b"foo".decode("latin1"),
            ],
        )

        CoreFoundation.CFArrayExchangeValuesAtIndices(array, 1, 2)
        self.assertEqual(
            array,
            [
                b"a".decode("latin1"),
                b"two".decode("latin1"),
                4,
                4,
                4,
                2,
                b"foo".decode("latin1"),
            ],
        )

        self.assertArgHasType(CoreFoundation.CFArrayReplaceValues, 2, b"n^@")
        self.assertArgSizeInArg(CoreFoundation.CFArrayReplaceValues, 2, 3)
        CoreFoundation.CFArrayReplaceValues(
            array,
            (2, 3),
            (
                b"a".decode("latin1"),
                b"b".decode("latin1"),
                b"c".decode("latin1"),
                b"d".decode("latin1"),
                b"e".decode("latin1"),
                b"f".decode("latin1"),
            ),
            6,
        )
        self.assertEqual(
            array,
            [
                b"a".decode("latin1"),
                b"two".decode("latin1"),
                b"a".decode("latin1"),
                b"b".decode("latin1"),
                b"c".decode("latin1"),
                b"d".decode("latin1"),
                b"e".decode("latin1"),
                b"f".decode("latin1"),
                2,
                b"foo".decode("latin1"),
            ],
        )

        array2 = CoreFoundation.CFArrayCreate(
            None,
            [b"hello".decode("latin1"), b"earth".decode("latin1")],
            2,
            CoreFoundation.kCFTypeArrayCallBacks,
        )
        CoreFoundation.CFArrayAppendArray(array, array2, (0, 2))
        self.assertEqual(
            array,
            [
                b"a".decode("latin1"),
                b"two".decode("latin1"),
                b"a".decode("latin1"),
                b"b".decode("latin1"),
                b"c".decode("latin1"),
                b"d".decode("latin1"),
                b"e".decode("latin1"),
                b"f".decode("latin1"),
                2,
                b"foo".decode("latin1"),
                b"hello".decode("latin1"),
                b"earth".decode("latin1"),
            ],
        )

        CoreFoundation.CFArrayRemoveAllValues(array)
        self.assertEqual(array, [])