Realization of GHZ states and the GHZ test via the interaction of atoms with cavity field states