'Common code for chown, fchown and lchown tests.'

def _test_all_chown_common(self, chown_func, first_param, stat_func):

    def check_stat(uid, gid):
        if (stat_func is not None):
            stat = stat_func(first_param)
            self.assertEqual(stat.st_uid, uid)
            self.assertEqual(stat.st_gid, gid)
    uid = os.getuid()
    gid = os.getgid()
    chown_func(first_param, uid, gid)
    check_stat(uid, gid)
    chown_func(first_param, (-1), gid)
    check_stat(uid, gid)
    chown_func(first_param, uid, (-1))
    check_stat(uid, gid)
    if (uid == 0):
        big_value = (2 ** 31)
        chown_func(first_param, big_value, big_value)
        check_stat(big_value, big_value)
        chown_func(first_param, (-1), (-1))
        check_stat(big_value, big_value)
        chown_func(first_param, uid, gid)
        check_stat(uid, gid)
    elif (platform.system() in ('HP-UX', 'SunOS')):
        raise unittest.SkipTest('Skipping    because    of    non-standard    chown()    behavior')
    else:
        self.assertRaises(OSError, chown_func, first_param, 0, 0)
        check_stat(uid, gid)
        self.assertRaises(OSError, chown_func, first_param, 0, (-1))
        check_stat(uid, gid)
        if (0 not in os.getgroups()):
            self.assertRaises(OSError, chown_func, first_param, (-1), 0)
            check_stat(uid, gid)
    for t in (str, float):
        self.assertRaises(TypeError, chown_func, first_param, t(uid), gid)
        check_stat(uid, gid)
        self.assertRaises(TypeError, chown_func, first_param, uid, t(gid))
        check_stat(uid, gid)
